Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test page doesn't replay animations #3

Closed
daneden opened this issue Oct 13, 2011 · 4 comments
Closed

Test page doesn't replay animations #3

daneden opened this issue Oct 13, 2011 · 4 comments

Comments

@daneden
Copy link
Collaborator

daneden commented Oct 13, 2011

Clicking on a test button on the home page more than once will not work - the user must click on another test, then return to the desired test.

It appears that the .removeClass().addClass() jQuery function is executing too quickly. I've also tried adding a relatively short delay, but no success.

@decthomas
Copy link

I had a similar problem with an animation that wouldn't play multiple times even though it had been triggered.
Adding animation-direction: alternate; to the CSS did the trick for me.

@daneden
Copy link
Collaborator Author

daneden commented Oct 13, 2011

@dec adding animation-direction: alternate didn't fix this unfortunately!

@millermedeiros
Copy link

it needs to happen on a timeout or you need to stop and remove the animation before setting a new one:

//"poor code" just to test on the console
$('.butt-small:first').click(function(evt){
  //just to block the current `onclick` and the link itself
  evt.preventDefault(); 
  evt.stopPropagation();

  var $at = $('#animateTest').removeClass();  
  //timeout is important !!
  setTimeout(function(){ 
    $at.addClass('flash') 
  }, 10); 
});

I would probably add a data-attribute to each button and create a generic click handler (and remove the "onclick" attributes):

<a href="#cta" class="butt butt-small butt-anim" data-anim="flash">flash</a>
jQuery(document).ready(function($){

    var destAnim = '',
        $animateTest = $('#animateTest');

    function animateOnClick(evt){
        $animateTest.removeClass();
        //need to add a `data-anim="animationName"` to each btn
        destAnim = $(this).data('anim');
        setTimeout(addDestAnimClass, 10);
    }

    function addDestAnimClass(){
        $animateTest.addClass(destAnim);
    }

    //need to add a class '.butt-anim' to each btn that toggles animations
    $('.butt-anim').live('click', animateOnClick);

});

I was going to fork it and do it but then I realized the project page isn't a gh-pages banch..

cheers.

@daneden
Copy link
Collaborator Author

daneden commented Apr 19, 2012

New demo page doesn't have this issue.

@daneden daneden closed this as completed Apr 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants