jquery在最后一张图片上停止
jquery stop on last image fadein
我正在执行三个图像的fadeIn和FadeOut。但当它到达最后一个时,它会返回到第一个。我想停留在最后一张照片上。我该怎么做?
$(document).ready(function(){
// run every 7s
setInterval('raiseToSunrise()', 1000);
});
function raiseToSunrise(){
var $active = $('#layout .active');
//var $next = ($active.next().length > 0) ? $active.next() : $('#layout img:first');
var $next = $active.next();
console.log($active.next().length);
$next.css('z-index',1);//move the next image up the pile
$active.fadeOut(8000,function(){//fade out the top image
$active.css('z-index',0).show().removeClass('active');//reset the z-index and unhide the image
$next.css('z-index',2).addClass('active');//make the next image the top one
});
}
#layout {
position:relative;
width:100%;
margin:0 auto;
}
#layout img {
position:absolute;
width:100%;
z-index:0;
}
#layout img.active
{
z-index:2;
}
<div id="layout">
<img class="active" id="nightimg" src="TemplateData/images/img_background_night.jpg" alt="myImage"/>
<img id="sunriseimg" src="TemplateData/images/img_background_sunrise.jpg" alt="myImage" />
<img id="dayimg" src="TemplateData/images/img_background_day.jpg" alt="myImage"/>
</div>
$(document).ready(function(){
// run every 7s
raiseToSunrise(8000)
});
function raiseToSunrise(interval){
var num = 1;
var theinterval = setInterval(function() {
var $active = $('#layout .active');
//var $next = ($active.next().length > 0) ? $active.next() : $('#layout img:first');
var $next = $active.next();
console.log($active.next().length);
$next.css('z-index',1);//move the next image up the pile
$active.fadeOut(8000,function(){//fade out the top image
$active.css('z-index',0).show().removeClass('active');//reset the z-index and unhide the image
$next.css('z-index',2).addClass('active');//make the next image the top one
});
num = num+1;
if(num == 4){
clearInterval(theinterval);
}
}, interval)
}
它不漂亮,可能效率也不高,但似乎有效。
相关文章:
- 为什么bxSlider会打断我在最后一张幻灯片和第一张幻灯片之间的转换
- 如何在最后一张幻灯片上停止动画
- 完整的背景图片幻灯片jquery,想让幻灯片的最后一张图片可以点击
- 指向html5库最后一张幻灯片后的html页面
- 附近搜索的标记仅显示在最后一张地图上
- 如何知道最后一张图片何时到达灯箱2
- 为什么我的 Jquery 轮播不会停留在最后一张图片上
- iOS 滑块默认为最后一张幻灯片
- 光滑的滑块删除最后一张幻灯片,如果 winWidth < 500
- Javascript幻灯片在节目开始时快速出现最后一张图像
- BX滑块滑块滑块最后一张幻灯片总是隐藏某些部分
- PrettyPhoto 图库中的最后一张图片首先加载
- 如何获取最后一张和第一张幻灯片以相应地激活或禁用下一个和上一个按钮
- 幻灯片放映-将幻灯片链接到URL,仅适用于最后一张幻灯片
- BxSlider将最后一张幻灯片显示为第一张幻灯片
- 停止最后一张幻灯片上的jQuery按钮动画
- 最后一张图片在图片库中闪烁
- 在页面加载时,不是显示第一张幻灯片,而是显示最后一张幻灯片不到一秒钟
- 更改最后一张图像的位置
- 轨道jquery滑块暂停在最后一张幻灯片