最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - pace.js: "start" event not triggered? - Stack Overflow

programmeradmin0浏览0评论

I can't seem to find a solution to this problem I posted in the comments of this question … I'm using the pace.js plugin and I would love to load/show parts of my page immediately without having to wait for the preloader to load all content.

I thought of doing this by simply calling the start event and show the selector immediately.

However I can't seem to find the cause why my done event is fired, but start is not. I also tried with hide which is also fired, but stop or restart is not.

$(window).load(function(){

    Pace.on('start', function() { 
        alert('start') // not fired
    });

    Pace.on('done', function() {
        alert('done') // fired!
    });

});

Any ideas?

I can't seem to find a solution to this problem I posted in the comments of this question … I'm using the pace.js plugin and I would love to load/show parts of my page immediately without having to wait for the preloader to load all content.

I thought of doing this by simply calling the start event and show the selector immediately.

However I can't seem to find the cause why my done event is fired, but start is not. I also tried with hide which is also fired, but stop or restart is not.

$(window).load(function(){

    Pace.on('start', function() { 
        alert('start') // not fired
    });

    Pace.on('done', function() {
        alert('done') // fired!
    });

});

Any ideas?

Share Improve this question edited Oct 6, 2021 at 15:41 Brian Tompsett - 汤莱恩 5,88372 gold badges61 silver badges133 bronze badges asked Dec 15, 2014 at 20:30 mattmatt 44.3k106 gold badges268 silver badges402 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 6

Call Pace.start(), right after event bindings. You then will be able to get the start event.

You will need to call

Pace.restart();

if the current page has already loaded with pace progress.

You have to put

Pace.on('start', function() { 
   alert('start');
});

outside $(window).load.... After that it will get start status, You are calling These methods after documentation is loaded so start must be already triggred.

after registering script and css, on your htlm section add this script

    <script type="text/javascript">
        window.onbeforeunload = renderLoading;
        function renderLoading() {
            Pace.stop();
            //Pace.start();
            Pace.bar.render();
        }
发布评论

评论列表(0)

  1. 暂无评论