Search code examples
javascriptjquery-effects

How to continuously bounce an object when site is live


I am new to JavaScript and jQuery. I have trouble in my new project. I want to need a image is bouncing. I got a script from net. But This function is only for jumping on the click.I want its jumping when the site is loaded. Please help me.

Link http://www.tycoonlabs.com/help/bouncing%20-%20Copy.html

This is my script

<SCRIPT>
$(function(){
    $('#bouncy1').click(function () {
          $(this).effect("bounce", { times:5 }, 300);
    });
});
</SCRIPT>

Thanks and Regards


Solution

  • If you want to have it bounce while something is happening and then stop it, you could use setInterval

    var interval = setInterval(function(){ 
        jQuery('#someId').effect('bounce', {times: 5}, 300);
    }, 500); // every half second
    
    // Do some stuff to load up your site;        
    
    clearInterval(interval); // Stop the bounce interval
    

    You may want to adjust the times parameter and the delay to meet your needs and effect.