Question

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

Was it helpful?

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.

OTHER TIPS

Try this:

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

this works well

function bounce(){
    $('#test').effect( "bounce", "slow", bounce);
}
bounce();

http://jsfiddle.net/xGe2D/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top