我有jquery我想延迟5秒的功能
$(target).slideDown("slow","linear", function(){
$(target).addClass('section-active');
$('html, body').animate({
scrollTop: $(target).offset().top
}, 1000, 'easeInOutExpo', function() {
isScrolling = false;
startNano.go();
});
});
我怎样才能实现
内置javascript setTimeout。你也可以使用.delay
方法来实现jquery 1.4.0+。 check it out here
setTimeout方法看起来像这样:
$(target).slideDown("slow","linear", function(){
setTimeout(function(){
$(target).addClass('section-active');
$('html, body').animate({
scrollTop: $(target).offset().top
}, 1000, 'easeInOutExpo', function() {
isScrolling = false;
startNano.go();
});
}, 5000); //5000 = 5 seconds
});
.delay
方法如下:
$(target).slideDown("slow","linear", function(){
$(target).addClass('section-active');
$('html, body').delay(5000).animate({
scrollTop: $(target).offset().top
}, 1000, 'easeInOutExpo', function() {
isScrolling = false;
startNano.go();
});
使用setTimeout()
。它在指定的毫秒数后调用函数或计算表达式
$(target).slideDown("slow","linear", function(){
setTimeout(function(){
$(target).addClass('section-active');
$('html, body').animate({
scrollTop: $(target).offset().top
}, 1000, 'easeInOutExpo', function() {
isScrolling = false;
startNano.go();
});
}, 5000); //5 seconds
});
使用setTimeout()
功能
setTimeout(function(){
$(target).slideDown("slow","linear", function(){
$(target).addClass('section-active');
$('html, body').animate({
scrollTop: $(target).offset().top
}, 1000, 'easeInOutExpo', function() {
isScrolling = false;
startNano.go();
});
});
},5000);
您可以使用.delay(5000)这是一个jQuery函数来链接动画或回调事件之间的延迟。
然而,正如(如果我已经正确理解)你希望它在它做任何事情之前等待,我们可以通过在我们要求它延迟然后链接结束之前设置一个stop()来解决这个问题。
$('html, body').stop(true, true).delay(5000).animate(...)