我检查了类似于我的其他帖子,但没有一个代码有效, 那么我怎样才能在动画之前为.css添加一些延迟
在这里你可以找到我的代码:
$(document).ready(function() {
$('.div2')
.css('visibility', 'visible') <-- // I WANT TO ADD HERE A DELAY BEFORE THE ANIMATION THAT IS BELOW STARTS !!!!
.animate({opacity: 1.0, left: '600px'}, 2000);
$('.div2').animate({opacity: 0.0, left: '600px'}, 2000, setInvisible);
});
function setInvisible() {
$('.div2').css('visibility', 'hidden');
}
我想延迟css,所以div会出现延迟,动画会稍后开始。
答案 0 :(得分:3)
如图所示使用.delay(): -
$('.div2')
.css('visibility', 'visible')
.delay(1000) //this time is in milliseconds increase or decrease as required.
.animate({opacity: 1.0, left: '600px'}, 2000);
或根据提问评论,请尝试使用setTimeout()
,如下所示: -
$(document).ready(function() {
setTimeout(function() {
$('.div2')
.css('visibility', 'visible')
.animate({opacity: 1.0, left: '600px'}, 2000);
},1500) //this time is in milliseconds increase or decrease as required.
});