<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery1.6.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(window).load(function() {
$(".pic li").each(function() {
var pwidth = $(this).width();
var pheight = $(this).height();
var _img = $(this).find("img");
var iwidth = _img.width();
var iheight = _img.height();
//alert(pwidth + "-" + pheight + "-" + iwidth + "-" + iheight)
if(pwidth <= iwidth || pheight <= iheight) {
if(iwidth/pwidth > iheight/pheight) {
_img.css("width",pwidth).css("height",pwidth/iwidth*iheight);
_img.css("margin-top",(pheight-pwidth/iwidth*iheight)/2+"px");
}
else {
_img.css("width",pheight/iheight*iwidth).css("height",pheight);
_img.css("margin-left",(pwidth-pheight/iheight*iwidth)/2+"px");
}
}
else {
_img.css("margin-left",(pwidth-iwidth)/2+"px");
_img.css("margin-top",(pheight-iheight)/2+"px");
}
})
})
})
</script>
<style type="text/css">
.pic {
overflow:hidden;
float:left;
}
.pic li {
list-style:none;
width:300px;
height:200px;
border:solid 1px #CCC;
float:left;
}
</style>
</head><body>
<div class="pic">
<ul>
<li><img src="image/xg.jpg" /></li>
<li><img src="image/wall6.jpg" /></li>
<li><img src="image/wall7.jpg" /></li>
</ul>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery1.6.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(window).load(function() {
$(".pic li").each(function() {
var pwidth = $(this).width();
var pheight = $(this).height();
var _img = $(this).find("img");
var iwidth = _img.width();
var iheight = _img.height();
//alert(pwidth + "-" + pheight + "-" + iwidth + "-" + iheight)
if(pwidth <= iwidth || pheight <= iheight) {
if(iwidth/pwidth > iheight/pheight) {
_img.css("width",pwidth).css("height",pwidth/iwidth*iheight);
_img.css("margin-top",(pheight-pwidth/iwidth*iheight)/2+"px");
}
else {
_img.css("width",pheight/iheight*iwidth).css("height",pheight);
_img.css("margin-left",(pwidth-pheight/iheight*iwidth)/2+"px");
}
}
else {
_img.css("margin-left",(pwidth-iwidth)/2+"px");
_img.css("margin-top",(pheight-iheight)/2+"px");
}
})
})
})
</script>
<style type="text/css">
.pic {
overflow:hidden;
float:left;
}
.pic li {
list-style:none;
width:300px;
height:200px;
border:solid 1px #CCC;
float:left;
}
</style>
</head><body>
<div class="pic">
<ul>
<li><img src="image/xg.jpg" /></li>
<li><img src="image/wall6.jpg" /></li>
<li><img src="image/wall7.jpg" /></li>
</ul>
</div>
</body>
</html>
解决方案 »
- 关于JS关闭窗口问题。
- 怎样使浏览器窗口一打开时实现最大化(要支持多浏览器)
- |zyciis| 如何监控一个checkbox的checked更改用onpropertychange的话在firefox中无效,谢谢 有代码
- 如何实现WebBrowser控件的自动横向打印设置?
- 一个简单问题,大家帮忙看看。
- 动态生成 全屏编辑列表 ,欢迎下载!
- 如何去掉图片上面的几个按钮?
- 关于scrollLeft的用法?
- 谁有ah__fu (阿福) 发的TreeView(tv2.0.js)源码共享一下
- 如何实现文本的打字特效,就是一个字一个字往外蹦.
- 为什么我的jquery图片滚动在ie6下越滚越慢……
- Jquery显示隐藏改变图片的问题
_img.css("width",pwidth).css("height",pwidth/iwidth*iheight);
_img.css("margin-top",(pheight-pwidth/iwidth*iheight)/2+"px");最好一次性修改_img.css({width:pwidth....})
因为每次修改几何属性,都会重绘和重排页面,性能损耗大