views:

29

answers:

2
Thats what i have so far i want to set a timeout for function spid()


 <script type="text/javascript">

$(document).ready(function() {  

$("#spid").animate({top: '-110px' }, 600, 'easeOutBounce',
function spid() {
$(this).animate({top:"-=20px"},1000).animate({top:"+=20px"},1000);
setTimeout("spid()",2000);
});

});
A: 

You just need to pass in a function.

setTimeout( spid,2000 );

Or you could also just use setInterval.

BBonifield
A: 
$(function() {
    $("#spid").animate({top: '190px' }, 600,'linear' ,function() {
        (function spid() { 
            console.log('Test'); 
            $(this).animate({top:"+=20px"},1000).animate({top:"+=20px"},1000);
            setTimeout(spid,2000);
        })();   
    });
});

There is a problem with this in the above code, below code snippet works fine

Edit :

$(function() {
  $("#spid").animate({top: '110px' }, 600,'linear' ,function() {
    var cache = $(this);
    (function spid() {
      cache.animate({top:"+=20px"},1000).animate({top:"-=20px"},1000);
      setTimeout(spid,2000);
    })();  
  });
});

please Test the code http://jsbin.com/elaxa3

Ninja Dude
it shows test,test,test
Noob
yep, which means that the code works fine. isn't it =)
Ninja Dude
yes it works but it dosent animate
Noob
this part of the code dosent work $(this).animate({top:"+=20px"},1000).animate({top:"+=20px"},1000);
Noob
nvm its not working when i put "#spid" instaed of "this" its works otherwise it dosent work
Noob
thanks it works
Noob
you're welcome noob, sorry I don't know your name =)
Ninja Dude