网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 dedecms图片撑破布局的解决方法
内容
    dedecms内容页图片过大,我们又不希望它不按比例的缩小,因为如果缩小不按比例,图片就会变形,所以我们需要找到一种等比例缩放图片的方法。
    第一步:打开include/arc.archives.class.php
    找到:
    //设置全局环境变量
    $this->fields['typename'] = $this->typelink->typeinfos['typename'];
    @setsysenv($this->fields['typeid'],$this->fields['typename'],$this->fields['id'],$this->fields['title'],'archives');
    在下面加入代码:
    //替换图片alt为文档标题
    $this->fields['body'] = str_ireplace(array('alt=','alt='''),'',$this->fields['body']);
    $this->fields['body'] = preg_replace(@ [s]{0,}alt[s]{0,}=['s]{0,}[ss]{0,}['s]
    @isu, ,$this->fields['body']);
    $this->fields['body'] = str_ireplace(<img ,<img alt=.$this->fields['title'].
    ,$this->fields['body']);
    //img标签中加入超宽缩小js调用代码
    $suolue='onload=javascript:imgresize(this)';
    $this->fields['body'] = str_ireplace(<img ,<img .$suolue. ,$this->fields['body']);
    //屏蔽height属性
    $this->fields['body'] = preg_replace('/<img(.+?)height=(.+?) (.+?)>/i',<img$1$3>,$this->fields['body']);
    第二步:打开你前台文章页模版,默认的是:/templets/default/article_article.htm,加入如下代码。那个600的数值,意思是当图片超过这个数值,自动将图片缩小,宽度缩小为600,高度自动按比例缩小,这样不会变形。
    <script language='javascript'>
    function imgresize(e)
    {
    if(e.width>600) //600可根据你文章的内容区域大小,可调整
    {
    e.width=600; //等同上面你设的那个数值
    e.style.width=;
    }
    if(e.height>10)
    {
    e.style.height=;
    }
    }
    </script> 
    到此,我们就全部修改好了,内容页图片太大导致布局混乱问题就解决了。
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/17 11:30:43