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

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

 

标题 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.$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/15 5:20:16