我正在尝试使用 jquery 淡入和淡出图像,但它不起作用,我遗漏了一些东西。
看下面的脚本:
var count = 1;
setInterval(function() {
count = (jQuery(".slideshow :nth-child("+count+")").fadeOut().next().length == 0) ? 1 : count+1;
//alert (count);
jQuery(".slideshow :nth-child("+count+")").fadeIn();
}, 2000);
这是 HTML 代码。
<div class="slideshow">
<div class="hover">
<a href="#">
<img src="#" />
<div class="mainportfo_title">title</div>
</a>
</div>
<div class="hover">
<a href="#">
<img src="#" />
<div class="mainportfo_title">title</div>
</a>
</div>
</div>
最佳答案
您可以使用 JQuery get() 并处理此 code , taht 绝对是可以改进的:
var i = 0;
setInterval(function() {
var target = $("img").get(i);
var next = $("img").get(++i);
$(target).fadeIn( "slow", function() {
$(target).fadeOut( "slow", function() {
$(next).fadeIn();
});
});
if(i >= $("img").size()) {
i = 0;
}
}, 3000);
关于javascript - jquery 在图像中淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25118773/