简体   繁体   English

将 CSS 预加载器添加到动态页面加载器

[英]Adding a CSS preloader to Dynamic Page loader

so I came across this snippet below which is fantastic at changing my pages within a div.所以我在下面看到了这个片段,它非常适合在 div 中更改我的页面。 However, I'm scratching my head on how I can do the following:但是,我正在摸索如何执行以下操作:

  1. make it so it fades in a CSS preloader egpreload ( https://projects.lukehaas.me/css-loaders/ )使它在 CSS 预加载器 egpreload ( https://projects.lukehaas.me/css-loaders/ ) 中消失
  2. it then to show this preloader for x amount of seconds然后将这个预加载器显示 x 秒
  3. Then for the preloader to fade out and show the content.然后让预加载器淡出并显示内容。

If anyone out there can help me point me in the right direction, a big thank you in advance.如果那里有人可以帮助我指出正确的方向,在此先非常感谢。

$(function() {

    if(Modernizr.history){

    var newHash      = "",
        $mainContent = $("#main-content"),
        $pageWrap    = $("#page-wrap"),
        baseHeight   = 0,
        $el;

    $pageWrap.height($pageWrap.height());
    baseHeight = $pageWrap.height() - $mainContent.height();

    $("nav").delegate("a", "click", function() {
        _link = $(this).attr("href");
        history.pushState(null, null, _link);
        loadContent(_link);
        return false;
    });

    function loadContent(href){
        $mainContent
                .find("#guts")
                .fadeOut(2000, function() {
                    $mainContent.hide().load(href + " #guts", function() {
                        $mainContent.fadeIn(1000, function() {
                            $pageWrap.animate({
                            });
                        });
                        $("nav a").removeClass("current");
                        console.log(href);
                        $("nav a[href$="+href+"]").addClass("current");
                    });
                });
    }

    $(window).bind('popstate', function(){
       _link = location.pathname.replace(/^.*[\\\/]/, ''); 
       loadContent(_link);
    });

} 


});

You should create a div on first level of body and the rest content could be added in sibling div.您应该在正文的第一级创建一个 div,其余内容可以添加到同级 div 中。 Keep this sibling div class hidden , in hidden class keep display: none.保持这个兄弟 div 类隐藏,在隐藏类中保持显示:无。

.hidden {
display: none;
}

When you want to close the loader, added hidden class to it and remove it from this sibling div.当你想关闭加载器时,向它添加隐藏类并将其从这个兄弟 div 中删除。 For smooth motion you could use CSS transition为了平滑运动,您可以使用 CSS 过渡

If you are using Jquery, then如果您使用的是 Jquery,那么

$(window).load(unHideContain)

this will call the unHideContain when window is loaded.这将在加载窗口时调用 unHideContain。 Till then a css generater loader or a full size loading .gif can display loading.直到那时 css 生成器加载器或全尺寸加载 .gif 可以显示加载。

Alternatively you can also use Jquery FadeIn或者,您也可以使用Jquery FadeIn

For doing it static timely as stated, which is not a good and recommeneded solution, you can do is为了按规定及时执行静态操作,这不是一个好的和推荐的解决方案,您可以做的是

window.setTimeout(unHideContain,5000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM