Search code examples
jquerylivejquery-animate

Trigger the jQuery animate with live()


I have a jQuery animation that is not working. I think the porblem comes from the parts that are the dynamic elements.

Is it possible to call the live() method with animate()?

Here's what I've go so far:

$(".tls").animate({"left": "-=50px"}, "slow");

Solution

  • I assume you have some kind of trigger for the animation?

    The code line you supplied will run the animation whenever the code line is reached in the code - what it seems you want, is to bind an animation to an element, and execute it later.

    Try, for example,

    $('.tls').on('click', function(ev) { 
        $(this).animate({left: '-=50px'}, 'slow'}); 
        // Add any necessary event handling here, for example
        ev.preventDefault();
        ev.stopPropagation();
    });