简单的褪色图像交换 [英] simple fading image swap
问题描述
我无法找到一个简单的jQuery图像交换。大多数我发现的例子比我需要的更复杂,并且做我不想要的东西。
目标:我想要淡入5张图片,幻灯片等等。我喜欢从一张图片淡入淡出/下一张图片,但幻灯片也可以。当第一次加载页面时,我想让第一张图片显示4秒钟......然后淡入到下一张图片,4秒钟,然后是下一个等等无限循环。
目前我的代码是一个简单的图像交换,不是很优雅:
document.getElementById(imgMain)。src =images / yurt / sleigh.png;
完成此操作的最佳和最简单的方法是什么?
以下是代码:
HTML
< div class =fadein>
< img src =http://farm9.staticflickr.com/8359/8450229021_9d660578b4_n.jpg>
< img src =http://farm9.staticflickr.com/8510/8452880627_0e673b24d8_n.jpg>
< img src =http://farm9.staticflickr.com/8108/8456552856_a843b7a5e1_n.jpg>
< img src =http://farm9.staticflickr.com/8230/8457936603_f2c8f48691_n.jpg>
< img src =http://farm9.staticflickr.com/8329/8447290659_02c4765928_n.jpg>
< / div>
CSS
.fadein {
position:relative;
height:320px;
width:320px;
}
.fadein img {
position:absolute;
剩下:0;
top:0;
JavaScript
$('。fadein img:gt(0)')。hide();
setInterval(function(){
$('。fadein:first-child')。fadeOut()
.next('img')
.fadeIn ()
.end()
.appendTo('。fadein');
},4000); // 4秒
I'm having trouble finding a simple jquery image swap. Most the examples I've found are more complex than I need, and do things I don't want.
Objective: I have 5 images I want to fade in, slide in, or etc. I would love to fade/dissolve from one image to the next, but slide would be fine too. When the page 1st loads, I want the 1st image to show for 4 seconds...then fade to the next image, 4 seconds, then the next, etc. Infinite loop.
Currently my code is a simple image swap, not very elegant:
document.getElementById("imgMain").src = "images/yurt/sleigh.png";
What's the best and simplest way to accomplish this?
Here's the code:
HTML
<div class="fadein">
<img src="http://farm9.staticflickr.com/8359/8450229021_9d660578b4_n.jpg">
<img src="http://farm9.staticflickr.com/8510/8452880627_0e673b24d8_n.jpg">
<img src="http://farm9.staticflickr.com/8108/8456552856_a843b7a5e1_n.jpg">
<img src="http://farm9.staticflickr.com/8230/8457936603_f2c8f48691_n.jpg">
<img src="http://farm9.staticflickr.com/8329/8447290659_02c4765928_n.jpg">
</div>
CSS
.fadein {
position:relative;
height:320px;
width:320px;
}
.fadein img {
position:absolute;
left:0;
top:0;
}
JavaScript
$('.fadein img:gt(0)').hide();
setInterval(function () {
$('.fadein :first-child').fadeOut()
.next('img')
.fadeIn()
.end()
.appendTo('.fadein');
}, 4000); // 4 seconds
这篇关于简单的褪色图像交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!