|
[分享]贡献一段内容页面代码 当图片超过设定值时 自动按比例缩小
代码如下:
<script type="text/javascript">
$(function() {
$(".contentzw img").each(function() {
var maxwidth = 800;
if ($(this).width() > maxwidth) {
var oldwidth = $(this).width();
var oldheight = $(this).height();
var newheight = maxwidth/oldwidth*oldheight;
$(this).css({width:maxwidth+"px",height:newheight+"px",cursor:"pointer"});
$(this).attr("title","点击查看原图");
$(this).click(function(){window.open($(this).attr("src"))});
}
});
})
</script>
代码解释:
内容页面 把正文内容div css 设置 contentzw 那么正文里的图片 宽超800px的话 就会按比例缩小 并且 鼠标在上面会有提示 点击查看原图 若宽度小于800 则按原大小显示
一看就知道 需要jq 支持 记得加上jq文件。。。。。
|
|