Jquery 图像淡入延迟 X
如何让我的图像一张一张地出现?我目前正在使用 Jquery fadein 使我的图像淡入,但我希望它们在不同的时间开始。无论如何,我可以延迟图像的淡入吗?几秒钟?
<script type="text/javascript">
$(document).ready(function(){
window.onload = function() {
$('.fader1').hide().fadeIn(3000);
$('.fader2').hide().fadeIn(9000);
$('.fader3').hide().fadeIn(6000);
};
});
</script>
<div class="fader1"><img src="demo.jpg"></div>
<div class="fader2"><img src="demo.jpg"></div>
<div class="fader3"><img src="demo.jpg"></div>
How can I get my images to appear one after the other? I am currently using Jquery fadein to make my images fadein but I want them to start at different times. Is there anyway i can delay an image from fading in? in seconds?
<script type="text/javascript">
$(document).ready(function(){
window.onload = function() {
$('.fader1').hide().fadeIn(3000);
$('.fader2').hide().fadeIn(9000);
$('.fader3').hide().fadeIn(6000);
};
});
</script>
<div class="fader1"><img src="demo.jpg"></div>
<div class="fader2"><img src="demo.jpg"></div>
<div class="fader3"><img src="demo.jpg"></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,有一个
delay
函数来实现这一点。他们开始的时间间隔一秒钟。
实时示例(使用下面稍微偏离主题的更新,以及稍微不同的延迟时间,但您明白了)
< strong>离题:我想我会在
window.onload
之前隐藏图像。只有当最后一个东西完全加载时才会触发,所以就像现在一样,大体上图像会出现,然后消失,然后淡入。您可以考虑在
< 的顶部执行此操作;body>
元素:并添加此 CSS:
然后
...或类似的。
Yes, there's the
delay
function for exactly that.That starts them one second apart.
Live example (using the slightly off-topic update below, and slightly different delay times, but you get the idea)
Off-topic: I think I'd hide the images earlier than
window.onload
. That'll only fire when every single last thing has fully loaded, so as it is now, by and large the images will appear, then disappear, then fade in.You might consider doing this right at the top of your
<body>
element:and adding this CSS:
then
...or similar.
您可以使用 fadeIn() 的回调在上一张图像完成时开始淡入下一张图像。尝试这样的事情:
但从已经隐藏的
参考: jquery fadeIn()
You could use fadeIn()'s callback to start the fading in of the next image just when the previous one completes. Try something like this:
but start with your <div>'s already hidden:
Refernce: jquery fadeIn()
http://api.jquery.com/delay/
.delay() 函数
http://api.jquery.com/delay/
.delay() function