1
我有几个动态加载的图像,宽度和高度被设置在代码中。显然它不会按比例扩展它们。这是我用代码加载动态图像:动态加载的图像的比例调整大小和垂直和水平居中
$(function(){
$.getJSON("inc/API.php", {command:"top3"}, function(result) {
for(var i = 0; i<result.length; i++) {
$("<div id='top3imgContainer'><a href='images/" + result[i].imageFileName + "' rel='shadowbox[top3]' title='"
+ result[i].imageHeader + "'><img width='220' height='220' src='images/" + result[i].imageFileName + "' id='top3img' /></a></div>").appendTo("#divTop3");
} Shadowbox.init({
continuous:true,
displayCounter:false,
overlayColor:"#a09e92",
overlayOpacity:0.8
});
});
});
的HTML:
<div id="divContent">
<div id="divTop3">
</div>
</div>
这是的CSS:
#divContent {
width:860px;
border: 1px solid;
border-color: #dbd9ca;
border-radius: 10px;
-moz-border-radius: 10px;
margin:5px;
margin-top:20px;
margin-bottom:20px;
padding:5px;
clear:both;
margin-bottom:20px;
}
#divTop3 {
width:850;
text-align:center;
position:relative;
}
#top3imgContainer {
width:245px;
height:270px;
background-image:url(../images_ui/frame.png);
background-repeat:no-repeat;
display:inline-block;
margin: 0 15px 0 15px;
}
img#top3img {
border-radius: 10px;
-moz-border-radius: 10px;
margin-left:13px;
margin-right:20px;
margin-top:17px;
}
和应用后这是CSS的外观: http://i44.tinypic.com/168x7i9.jpg
不是完全正比,也不是真正居中。 所以问题是 - 我怎样才能按比例调整它们呢?之后 - 我怎样才能在每个图像的中心?
谢谢!
非常感谢您的答复!是的,这几乎是诀窍!我想我会需要很多JS来按比例调整图像大小......再次,谢谢! PS。我仍然不被允许投票答复...对不起! :( – Igal 2012-03-05 07:44:34
高兴地帮助:)您不必提高答案,只需点击向上/向下箭头下方的空白勾号即可。并且确实可以在每个浏览器中检查解决方案,因为其中一些(希望只有较老的)才将图像拉伸至最大宽度/高度。 – biziclop 2012-03-05 08:39:08
明白了吧! :)并再次感谢,也为浏览器兼容性的建议!将研究它! – Igal 2012-03-05 23:27:07