search
HomeCMS TutorialDEDECMSHow does dedecms make pictures adapt to the screen size?

How does dedecms make pictures adapt to the screen size?

许多使用过织梦dedecms建网站的朋友,可能都会碰到过这样的情况,当我们在一个网站里发表一篇文章时,如果我们使用的图片,其宽度超过内容区域大小,图片就会将表格撑大,同时使得页面布局变得混乱起来。当然,如果懂CSS,我们可以利用css来定义,让超出的部分隐藏起来。不过,这样做的话,图片的美观性就很差,显示不出来超出的部分。

解决这个问题,还有一些朋友,会利用css,使图片在过大后,自动将图片缩小,不过,值得注意的是,由于CSS对各个浏览器存在兼容问题,所以就拿IE6浏览器来说,其作用就不大。

下面我们来看一种好方法。

第一步,打开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,}[\s\S]{0,}[\"'\s]
@isU"," ",$this->Fields['body']);
$this->Fields[&#39;body&#39;] = str_ireplace("<img " ,"<img alt=\"".$this->Fields[&#39;title&#39;]."\"
",$this->Fields[&#39;body&#39;]);

//img标签中加入超宽缩小JS调用代码

$suolue=&#39;οnlοad="javascript:ImgReSize(this)"&#39;;
$this->Fields[&#39;body&#39;] = str_ireplace("<img  " ,"<img ".$suolue." ",$this- alt="How does dedecms make pictures adapt to the screen size?" >Fields[&#39;body&#39;]);
//屏蔽height属性
$this->Fields[&#39;body&#39;] = preg_replace(&#39;/<img (.+?)height=(.+?) (.+?) alt="How does dedecms make pictures adapt to the screen size?" >/i&#39;,"<img $1$3 alt="How does dedecms make pictures adapt to the screen size?" >",$this->Fields[&#39;body&#39;]);

第二步:打开你前台文章页模版,默认的是:/templets/default/article_article.htm(有的朋友,仿完站,内容页的模版未必是这个默认的)打开模版后将下面代码插入到 中 ,注意那个670的数值,这个值意思是当图片超过这个数值,自动将图片缩小,宽度缩小为670,高度自动按比例缩小,这样不会变型。

<script language=&#39;javascript&#39;>
function ImgReSize(e)
{
if(e.width>670) // 670可根据你文章的内容区域大小,可调整
{
e.width=670; // 等同上面你设的那个数值
e.style.width="";
}
if(e.height>10)
{
e.style.height="";
}
}
</script>

到这里,就可以了,如果你懂CSS最好找到内容区域的CSS,将它的宽设定好,然后定义一下,超出部分隐藏,因为有时候,文章在加载的过程中,显示的是你原始大小,加载完成后,JS才会起作用,将图片缩小。

更多DedeCMS相关技术文章,请访问DedeCMS教程栏目进行学习!

The above is the detailed content of How does dedecms make pictures adapt to the screen size?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools