2

I'm putting together a simple site and I want to use the nice transitions from SmoothState.js, but I also use other jQuery scripts (such as Flexslider) that I have set up to fire on $(document).ready() -- and now that my transitions are nice and smooth, the other JS is no longer firing.

I've tried placing this at the beginning of all my pages (taken from here):

(function($, undefined) {
    var isFired = false;
    var oldReady = jQuery.fn.ready;
    $(function() {
        isFired = true;
        $(document).ready();
    });
    jQuery.fn.ready = function(fn) {
        if(fn === undefined) {
            $(document).trigger('_is_ready');
            return;
        }
        if(isFired) {
            window.setTimeout(fn, 1);
        }
        $(document).bind('_is_ready', fn);
    };
})(jQuery);

But they're still not firing properly.

What am I missing?

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289

1 Answers1

1

Turns out my problem was that I was loading fresh JavaScript in the header of my new pages, which wasn't being picked up. By moving it into a central file that's loaded on every initial page load, everything works peachy.

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
  • You just need to move your JS into within the scope of your SmoothState element. If it's outside it then it won't get fired. Also make sure you place it in a self-executing function. Eg. `(function() { alert('Hello World'); })(); ` – Chuck Le Butt Apr 20 '15 at 16:08
  • I load my scripts in the footer just before the

    so do you mean i need to load it inside the .m-scene class?

    – benpalmer Aug 19 '15 at 16:35