Curious about the new way YouTube is loading pages

前端 未结 3 1392
死守一世寂寞
死守一世寂寞 2020-12-22 16:17

I\'ve noticed when I\'m watching a video and I click on the logo or a related video that a red progress bar (above the logo) dashes across the screen. At the same time there

3条回答
  •  旧时难觅i
    2020-12-22 17:03

    looking at this demo, maybe could help you, and look at the comments, some say nice while some say too complicate to achieve it

    html:

    css:

    #progress {
        position: fixed;
        z-index: 2147483647;
        top: 0;
        left: -6px;
        width: 1%;
        height: 2px;
        background: #0088CC;
        -moz-border-radius: 1px;
        -webkit-border-radius: 1px;
        border-radius: 1px;
        -moz-transition: width 500ms ease-out,opacity 400ms linear;
        -ms-transition: width 500ms ease-out,opacity 400ms linear;
        -o-transition: width 500ms ease-out,opacity 400ms linear;
        -webkit-transition: width 500ms ease-out,opacity 400ms linear;
        transition: width 500ms ease-out,opacity 400ms linear;
    }
    
    
    #progress dd, #progress dt {
        position: absolute;
        top: 0;
        height: 2px;
        -moz-box-shadow: #0088CC 1px 0 6px 1px;
        -ms-box-shadow: #0088CC 1px 0 6px 1px;
        -webkit-box-shadow: #0088CC 1px 0 6px 1px;
        box-shadow: #0088CC 1px 0 6px 1px;
        -moz-border-radius: 100%;
        -webkit-border-radius: 100%;
        border-radius: 100%;
    }
    
    #progress dt {
        opacity: .6;
        width: 180px;
        right: -80px;
        clip: rect(-6px,90px,14px,-6px);
    }
    
    #progress dd {
        opacity: .6;
        width: 20px;
        right: 0;
        clip: rect(-6px,22px,14px,10px);
    }  
    

    js:

    $(document).ajaxStart(function() {
    //only add progress bar if added yet.
      if ($("#progress").length === 0) {
        $("body").append($("
    ").attr("id", "progress")); $("#progress").width((50 + Math.random() * 30) + "%"); } }); $(document).ajaxComplete(function() { //End loading animation $("#progress").width("101%").delay(200).fadeOut(400, function() { $(this).remove(); }); });

提交回复
热议问题