Wednesday, October 8, 2014

Bouncing ball using jquery every seconds

Create a bouncing ball using jquery. The div moves up after 1 second and move down after.
$(function () {
    toggle=1;
 function bounce(){ 
            if(toggle == 1){
                $(".ball").animate({top:'-=80px'}, 1000); 
                toggle = 0;
            }else{
                $(".ball").animate({top:'+=80px'},1000); 
                toggle = 1;
            }
        }
  setInterval(bounce, 800);
});
Live Demo

No comments:

Post a Comment