0

I'm not that experienced with jQuery and I'm having some difficulty triggering an animation from the animate.css library. I've got it to work using clicks, but not in the area I want.

Here's the function that works with clicking:

$(function() {
    var animation_name = 'animated shake';
    var animation_end = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';

    $('#link-add').on('click',function() {
        $('#add-paypal').addClass(animation_name).one(animation_end,function() {
            $(this).removeClass(animation_name);
        });
    });
});

And here's where I want to make it work:

$('#add-link').on('change', function() {

    var animation_name = 'animated shake';
    var animation_end = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';

    var link = $('#add-link').val();
    var paypal = $('#add-paypal').val();

    if (! paypal)
    {
        //Animate #add-paypal
    };
    else
    {
        //Animate #link-add
    };
});
1
  • 1
    Happy New Year by the way :) Commented Jan 1, 2016 at 11:46

2 Answers 2

3

animate.css provides css animation classes which are triggered when added to element so to trigger it you simply do

$('#add-paypal').addClass(animation_name);

but if you want to know when animation finished you can listen to event

$('#add-paypal').addClass(animation_name)
  .one(animation_end, function(){ 
    $(this).removeClass(animation_name);
  });
Sign up to request clarification or add additional context in comments.

Comments

1

You just need to identify the element on which the animation is to be triggered on and parallelly keeping it simplified.

$('#add-link').on('change', function() {

    var animation_name = 'animated shake';
    var animation_end = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';

    var link = $('#add-link').val();
    var paypal = $('#add-paypal').val();

    if (! paypal)
    {
        var el = paypal;
    };
    else
    {
        var el = link;
    };

    if(el)
        el.addClass(animation_name).one(animation_end,function() {
            $(this).removeClass(animation_name);
        });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.