admin管理员组文章数量:1291146
I'm having trouble finding a simple jquery image swap. Most the examples I've found are more plex 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 acplish this?
I'm having trouble finding a simple jquery image swap. Most the examples I've found are more plex 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 acplish this?
Share Improve this question edited Feb 10, 2013 at 6:38 Jeff Miller 2,4431 gold badge29 silver badges42 bronze badges asked Feb 10, 2013 at 5:27 HerrimanCoderHerrimanCoder 7,22630 gold badges95 silver badges170 bronze badges 1- 1 Pick a plugin. Any plugin. It doesn't matter which one. There are plenty to pick from. Now use it, and move on to solving problems which are actually interesting. – Matt Ball Commented Feb 10, 2013 at 5:29
1 Answer
Reset to default 6Working example on jsFiddle.
Here's the code:
HTML
<div class="fadein">
<img src="http://farm9.staticflickr./8359/8450229021_9d660578b4_n.jpg">
<img src="http://farm9.staticflickr./8510/8452880627_0e673b24d8_n.jpg">
<img src="http://farm9.staticflickr./8108/8456552856_a843b7a5e1_n.jpg">
<img src="http://farm9.staticflickr./8230/8457936603_f2c8f48691_n.jpg">
<img src="http://farm9.staticflickr./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
本文标签: javascriptsimple fading image swapStack Overflow
版权声明:本文标题:javascript - simple fading image swap - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741519439a2383092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论