我是关于javascript和jquery的新手,我在这个小提琴上创建了一些函数,它只运行一次,如何循环这个函数?
$(document).ready(function() // function
{
$('.box').css({visibility:'hidden'});
setTimeout( function(){
$('.box-1').css({visibility:'visible'});
},300);
setTimeout( function(){
$('.box-2').css({visibility:'visible'});
},600);
setTimeout( function(){
$('.box-3').css({visibility:'visible'});
},900);
setTimeout( function(){
$('.box').fadeOut('slow');
},1300);
})
答案 0 :(得分:4)
使用setInterval()
$(document).ready(function () {
function animate() {
$('.box').css({
visibility: 'hidden',
display: ''
});
setTimeout(function () {
$('.box-1').css({
visibility: 'visible'
});
}, 300);
setTimeout(function () {
$('.box-2').css({
visibility: 'visible'
});
}, 600);
setTimeout(function () {
$('.box-3').css({
visibility: 'visible'
});
}, 900);
setTimeout(function () {
$('.box').fadeOut('slow');
}, 1300);
}
animate()
setInterval(animate, 1800)
});
演示:Fiddle