我是靠谱客的博主 独特草莓,这篇文章主要介绍jquery实现图片等比例缩放以及max-width在ie中不兼容解决,现在分享给大家,希望可以做个参考。

上次用原生的JavaScript实现的图片等比例缩放,max-width和max-height在ie6中不兼容问题,今天用jQuery实现了这些问题

jQuery部分代码

复制代码 代码如下:

<script type="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>

最后

以上就是独特草莓最近收集整理的关于jquery实现图片等比例缩放以及max-width在ie中不兼容解决的全部内容,更多相关jquery实现图片等比例缩放以及max-width在ie中不兼容解决内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(175)

评论列表共有 0 条评论

立即
投稿
返回
顶部