【发布时间】:2012-04-19 01:46:01
【问题描述】:
如果我的代码如下所示,如何自动调整图像:
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function () {
var count = 0;
function animate() {
jQuery(".fadein").eq(count).fadeIn(1000);
count++;
if(count <= jQuery(".fadein").length) {
setTimeout(animate, 1000);
} else {
jQuery("a.fadein").fadeOut(1000);
count = 0;
animate();
}
}
animate();
});
</script>
这是正确的吗?
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function () {
var count = 0;
function animate() {
jQuery(".fadein").eq(count).fadeIn(1000);
count++;
if(count <= jQuery(".fadein").length) {
setTimeout(animate, 1000);
} else {
jQuery("a.fadein").fadeOut(1000);
count = 0;
animate();
}
}
animate();
})
function fitImagetoContainer() { $("img").each(function(i) {
$(this).width($(this).parent().width()); //or your logic
}); }
//Call the function at load
$(window).load(function() { fitImagetoContainer(); });
//Also call the function when the window resizes
$(window).resize(function() { fitImagetoContainer(); });;
</script>
【问题讨论】:
-
我认为你在那里缺少一些标记。
-
自动调整是什么意思?如果图像比容器小,比容器大,你希望发生什么?
-
@arasmussen:我的意思是,如果我调整浏览器的大小,那么图像也会跟随图像的大小。这可能吗?
-
@Marcel:我在 HTML 中做了一部分
-
你能链接到你所拥有的演示吗? JavaScript 只是这个难题的一部分。例如,一些基本的 CSS 可能会解决您的问题。
标签: jquery html image image-size