Search code examples
javascriptpreload

Only use pace.js on first page (initial site load)


Using the plugin pace.js (http://github.hubspot.com/pace/), I wish only to use it to preload the first page of a site. Been looking through the options but there doesn't seem to be a built-in way to do this, but only toggling pushstate and ajax preloads.

Also, for some reason the preloader bar ends about 50% of its width when preloading a page. This probably has to do with the site being run locally, although I use multiple external elements and images. Anyone else experiencing this?


Solution

  • here is my way of doing it. you may put in how you implemented that.

    <script> $(window).load(function(e){ $('div.loading-page').fadeOut('slow'); }); </script>
    <div class="loading-page"></div>
    

    css:

    .loading-page{
        position:fixed;
        top:0;
        bottom:0;
        left:0;
        right:0;
        background:white;
        z-index:1999; /* as pace has 2000 */
    }