联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

jquery实现图片等比例缩放以及max-width在ie中不兼容解决 - Web前端

作者:98wpeu发布时间:2026-08-06分类:网页前端技术浏览:3


导读:上次用原生的JavaScript实现的图片等比例缩放,max-width和max-height在IE6中不兼容问题,今天用JQuery实现了这些问题jQuery部分代码复制代码...
上次用原生的JavaScript实现的图片等比例缩放,max-width和max-height在IE6中不兼容问题,今天用JQuery实现了这些问题

jQuery部分代码
复制代码 代码如下:
<scripttype="text/javascript">
$(document).ready(function(){
var maxWidth=$(".imgBox").width();
$("img").each(function(){
if(!$.support.style&&$.browser.msie&&($.browser.version==6.0)){ //判定浏览器为IE6的时候
var imgwidth=$(this).width();
var imgHeight=$(this).height();
var maxHeight = maxWidth*imgHeight/imgWidth;
if(imgWidth>maxWidth){
$(this).CSS("width",maxWidth).css("height",maxHeight);
}
}
})
})
</script>

css部分代码:
复制代码 代码如下:
<style type="text/css">
body{ margin:0; padding:0;}
.box{ width:700px; margin:0 auto;}
.imgBox{ background:#CCCCCC;*display:table-cell; width:400px; margin:10px auto; *font-size:350px; line-height:400px; text-align:center; vertical-align:middle; padding:20px;}
img{ border:0 none; max-width:400px; overflow:hidden; vertical-align:middle;}
</style>

html代码:
复制代码 代码如下:
<div class="box">
<div class="imgBox">
<img src="images/12.jpg" alt="等比例缩放图片"/>
</div>
</div>

标签:缩放中不图片等比例Webwidth


网页前端技术排行
最近发表
网站分类
标签列表