WillingLearner
WillingLearner

Reputation: 7316

Need jquery to animate immediately on page load instead of on click

I'm using this code:

<!-- language: lang-js -->
$(document).ready(function() {

    $("#Arrow_Down_Mobile , #Arrow_Down_Mobile_other").click(function() {
      doBounce($(this), 10, '10px', 300);
    });


    function doBounce(element, times, distance, speed) {
      for (var i = 0; i < times; i++) {
        element.animate({
          marginTop: '-=' + distance
        }, speed).animate({
          marginTop: '+=' + distance
        }, speed);
      }
    }

});

It works perfectly fine, however I'm trying to change the behavior from click() so that it can start playing immediately once the page loads.

I've tried ready, live(), trigger(), on(), load() etc. yet none of them play the animation right away so I'm running out of ideas here as to how to get this animation to work other than by clicking on it.

Upvotes: 1

Views: 31

Answers (1)

cantuket
cantuket

Reputation: 1592

$(document).ready(function (){
   doBounce($("#Arrow_Down_Mobile , #Arrow_Down_Mobile_other"), 10, '10px', 300)
});

We can't see your attempt to implement the ready() method, but make sure you're calling it on the document object.

Upvotes: 1

Related Questions