denehyg / reveal.js-menu

Slide out menu for reveal.js
https://denehyg.github.io/reveal.js-menu
MIT License
281 stars 76 forks source link

Slidecahnged events don't trigger when using plugin #28

Closed Bartket closed 7 years ago

Bartket commented 7 years ago

I am using small jquery function to make a simple countup animation in my presentation but when I use menu plugin it suddenly stops to work and trigger only on the slide refresh but not when I change the slide. I tried to reslove the issue but without any luck.

code:

    <script>
             Reveal.addEventListener( 'slidechanged', function( event ) {
             if(event.indexh == 5){
             $('.count').each(function () {
                     $(this).prop('Counter',0).animate({
                             Counter: $(this).text()
                     }, {
                             duration: 3000,
                             easing: 'swing',
                             step: function () {
                                     $(this).text(Math.ceil(this.Counter))
                             }
                     });
             });
            }
            });
            </script>
Bartket commented 7 years ago

Issue solved by adding Jquery as dependency in async mode.

    dependencies: [
                    { src: 'plugin/extras/jquery.min.js', async: true},

Edit: Okay that didn't really solve the issue because when I load jquery in async mode the menu doesn't load properly and I can't pick slides since all of them load at once after click. The conclusion is that the menu does not work properly with jquery.min.js library loaded. I just decided to use some other script library for counter and it works properly now.

denehyg commented 7 years ago

This is because I've used ender which uses the $ namespace, as does jquery. I expect that whichever library is loaded last is taking over $, prevent the other from working properly.

You should be able to use jquery still following this... https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

I'll look into how best to remove the conflict from within reveal.js-menu at some point in the future.