matthieua / WOW

Reveal CSS animation as you scroll down a page
https://www.delac.io/WOW/
9.91k stars 4.12k forks source link

Repeat Animation for Modals #197

Open Chris-Reedy opened 9 years ago

Chris-Reedy commented 9 years ago

I would like to run WOW Animate when opening up a modal to animate its contents. This works, but by design, WOW doesn't do this after its run once. I can understand for default use, but where modals are concerned, is there a code edit that can be used where I can have them animate each time a certain modal is opened? For instance, right now, if I click open modal 1 the animation runs. Great! But once I close and reopen the same modal without refreshing the page, the animation doesn't run again since it already has. I'd like it to. Is there a reload code? I know you want to keep this plugin light, but curious if this is possible. Thanks!

Chris-Reedy commented 9 years ago

So it looks like it DOES reload each time, but ONLY if I add: data-wow-duration=".3s" to the div wow code. [1] Or am I crazy? [2] If I'm not crazy, that's good, but doing this gives me that flash people see and solve by .wow {visibility:hidden;} - even though I already have that in my .css and it solves the flash problem when not in the modal. This flash occurs only in the modal now.

Chris-Reedy commented 9 years ago

I was able to repeat the wow animation each time a modal opens without flash by adding the stop and init code to my modal open code, like this example:

$(document).ready(function(){
    $('.info').on('click', function ( e ) {
        wow.stop();
        wow = new WOW(
                {
                boxClass:     'wow',      // wow
                animateClass: 'animated', // animated
                offset:       0,          // 0
                mobile:       true,       // true
                live:         true        // true
                }
            );
        wow.init();
        Custombox.open({
            target: $(this).data('href'),
            effect: 'push',
            speed: 500,
            overlayColor: '#2C3E50',
        });
        e.preventDefault();
    });
});
</script>
Chris-Reedy commented 9 years ago

RATS! So close.

I have a grid of boxes. Each box is a trigger that opens a modal. Inside each modal are items that appear with WOW.

My above "solution" did work, but only for boxes (modal triggers) that WOW already loaded. If I scroll down and WOW loads more boxes (modal triggers), the modal is empty when opened. It's like WOW isn't restarting for hidden items...

Can anyone help?

jh-sh commented 9 years ago

I think you misuse wow.js.. AFAIK, It's not supposed to animate modals appearance by design (it triggers class changes, if element hits the viewport with specified options) I could've gotten you wrong - maybe you're about animating the content inside the pop-up (while scrolling) Anyway: You can still manually toggle classes while triggering pop-ups appearances (using same animate.css file), for example - remove .animated class after pop-up faded out.

Chris-Reedy commented 9 years ago

I'm not trying to animate the modal's appearance. I'm using it as it is designed, as you explained, to trigger class changes if the element hits the viewport.

Here is how I have it:

What I want to accomplish is:

I got this to work (see above), but there was a side effect:

So you are saying that I can use .addClass('.animated') and .removeClass('.animated') on my modal trigger code to accomplish what I want instead of using wow.stop() and wow.init()?

Chris-Reedy commented 9 years ago

EXAMPLES

[1] Here is a development page of how it works with no changes to any code: http://www.shynemedia.com/dev/sm/2015_site/portfolio/logos/index.php

[2] Here is a development page of how it works if I add code so the animation repeats on modal open: http://www.shynemedia.com/dev/sm/2015_site/portfolio/logos/index2.php

It feels like the wow plugin isn't fully restarted or that it's a timing issue - I'm stumped.

Hope this makes it more clear...