我正在使用 Chris Coyier 的这个非常基本的褪色幻灯片:http: //css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/
一切正常,除了我想要多个幻灯片,每个都是缩略图。所以当我添加多个相同的东西时,它就坏了。我注意到它使用id
,slideshow
和id
s 必须是唯一的,所以我把它改成了class
. 现在一切正常,但似乎破坏了fadeIn()
andfadeOut()
功能?或者至少,这似乎是它所做的。这是一个小提琴:http: //jsfiddle.net/QRZKE/
HTML:
<div class="thumb" id="first">
<span><img src="http://thebarking.com/wp-content/uploads/2012/09/biscuit.jpg"></span>
<div><img src="http://31.media.tumblr.com/tumblr_m33f16g9Li1r21nejo1_400.jpg"></div>
<div><img src="https://www.creameryschoolofmusic.com/template/upload_images/Guitar-guitar-10566054-1920-1200.jpg"></div>
</div>
<br>
<div class="thumb" id="second">
<span><img src="http://thebarking.com/wp-content/uploads/2012/09/biscuit.jpg"></span>
<div><img src="http://31.media.tumblr.com/tumblr_m33f16g9Li1r21nejo1_400.jpg"></div>
<div><img src="https://www.creameryschoolofmusic.com/template/upload_images/Guitar-guitar-10566054-1920-1200.jpg"></div>
</div>
<br>
<div class="thumb" id="third">
<span><img src="http://thebarking.com/wp-content/uploads/2012/09/biscuit.jpg"></span>
<div><img src="http://31.media.tumblr.com/tumblr_m33f16g9Li1r21nejo1_400.jpg"></div>
<div><img src="https://www.creameryschoolofmusic.com/template/upload_images/Guitar-guitar-10566054-1920-1200.jpg"></div>
</div>
<br>
<div class="thumb" id="fourth">
<span><img src="http://thebarking.com/wp-content/uploads/2012/09/biscuit.jpg"></span>
<div><img src="http://31.media.tumblr.com/tumblr_m33f16g9Li1r21nejo1_400.jpg"></div>
<div><img src="https://www.creameryschoolofmusic.com/template/upload_images/Guitar-guitar-10566054-1920-1200.jpg"></div>
</div>
<br>
<div class="thumb" id="fifth">
<span><img src="http://thebarking.com/wp-content/uploads/2012/09/biscuit.jpg"></span>
<div><img src="http://31.media.tumblr.com/tumblr_m33f16g9Li1r21nejo1_400.jpg"></div>
<div><img src="https://www.creameryschoolofmusic.com/template/upload_images/Guitar-guitar-10566054-1920-1200.jpg"></div>
</div>
CSS:
.thumb {
position: relative;
width: 240px;
height: 240px;
padding: 10px;
background: white;
box-shadow: 0 0 20px rgba(0, 0, 0, .4);
}
.thumb > div {
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
z-index: 2;
}
.thumb > span {
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
z-index: 3;
-webkit-transition: all .65s ease-in;
-moz-transition: all .65s ease-in;
-ms-transition: all .65s ease-in;
-o-transition: all .65s ease-in;
transition: all .65s ease-in;
}
.thumb > span:hover {
opacity: 0;
}
.thumb img {
height: 240px;
width: 240px;
}
JavaScript:
$(document).ready(function() {
$(".thumb > div:gt(0)").hide();
setInterval(function() {
$(".thumb > div:first")
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo(".thumb");
}, 2500);
});
注意:我在 some span
s 中添加了一个图像,它覆盖了幻灯片,你必须将鼠标悬停在它上面才能让它消失(好像在悬停它之后开始幻灯片)。
有任何想法吗?任何帮助将非常感激。
编辑:我发现如果我删除其他幻灯片(只有一个),淡入淡出效果很好。只有一次我添加多个。但是类可以是非唯一的,对吧?那么为什么脚本会中断呢?(而且它不像实际的脚本正在破坏,它只是淡入淡出的效果,否则滑块工作正常!)