代码之家  ›  专栏  ›  技术社区  ›  Jason

退出/外部链接启动页/页面加载

  •  2
  • Jason  · 技术社区  · 14 年前

    我以前在网站上看到过,当你点击一个链接时,一个加载页面/启动页面会消失,然后新页面就会消失。不幸的是,我不记得我在哪里看到这个了,否则我就把他们的切除了。

    有人知道用jquery、mootools、ajax脚本来做这个吗?

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  1
  •   Robert    14 年前

    这个脚本将淡出你的页面容器,淡入加载页面(你的启动屏幕)。启动屏幕加载后,它会对内容发出AJAX请求。完成后,它会从启动屏幕淡入新页面。

    $('#wrapperForThePage').click(function() {
        $('#wrapperForThePage').fadeOut(function() {
            $('#loadingSplash').fadeIn();
            $('#wrapperForThePage').load("yourpage.html", function() {
                $('#loadingSplash').fadeOut(function() {
                    $('#wrapperForThePage').fadeIn(); // Called on complete, 404 or success
                });
            });
        });
    });​
    

    http://jsfiddle.net/4KRpE/

        2
  •  2
  •   Oskar Krawczyk    14 年前

    用MooTools做的更复杂的事情: http://www.jsfiddle.net/oskar/rDrtP/

    var contentEl = $('content'),
        loaderEl = $('loader'),
        navEls = $$('#nav a');
    
    var loadContent = function(){
    
        // fade out the container
        contentEl.fade('out');
    
        // show the loader
        loaderEl.set('opacity', 0).fade('in');
    
        // fetch the new content
        new Request.HTML({
            url: this.get('href'),
            onComplete: function(responseEls){
    
                // empty the previous content and inject the new one
                contentEl.empty().adopt(responseEls);
    
                // show the content
                contentEl.fade('in');
    
                // hide the loader
                loaderEl.fade('out');
            }
        }).post({
            html: '<strong>' + this.get('html') + '</strong>'
        });
    };
    
    navEls.each(function(nav){
        nav.addEvents({
            click: function(e){
                e.stop();
    
                // load new content when clicking the links
                loadContent.bind(this).run();
            }
        });
    });​