javascript - 如何像预加载器一样实现 Youtube

标签 javascript html css preloader

我在 YouTube 上遇到了一个预加载器,它看起来像这样 YouTube Preloader

我喜欢在我的网站上实现这种类型的预加载器,找不到如何实现这种类型的预加载器,它根据屏幕尺寸和主题[深色或正常]而变化

Small Screen and default theme

我已经实现了这样的普通预加载器

$(window).on('load', function () {
    $('#preloader').delay(350).fadeOut('slow');
    $('body').delay(350).css({ 'overflow': 'visible' });
}) 

任何人都可以帮助找到使用的预加载器的类型,是这张图片还是其他东西。

最佳答案

这些叫做骨骼加载预加载器,你可以引用this示例还考虑使用 this library用于轻松创建此类预加载器。

.timeline-item {
    background: #fff;
    border: 1px solid;
    border-color: #e5e6e9 #dfe0e4 #d0d1d5;
    border-radius: 3px;
    padding: 12px;

    margin: 0 auto;
    max-width: 472px;
    min-height: 200px;
}

@keyframes placeHolderShimmer{
    0%{
        background-position: -468px 0
    }
    100%{
        background-position: 468px 0
    }
}

.animated-background {
    animation-duration: 1s;
    animation-fill-mode: forwards;
    animation-iteration-count: infinite;
    animation-name: placeHolderShimmer;
    animation-timing-function: linear;
    background: #f6f7f8;
    background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
    background-size: 800px 104px;
    height: 96px;
    position: relative;
}

.background-masker {
    background: #fff;
    position: absolute;
}

/* Every thing below this is just positioning */

.background-masker.header-top,
.background-masker.header-bottom,
.background-masker.subheader-bottom {
    top: 0;
    left: 40px;
    right: 0;
    height: 10px;
}

.background-masker.header-left,
.background-masker.subheader-left,
.background-masker.header-right,
.background-masker.subheader-right {
    top: 10px;
    left: 40px;
    height: 8px;
    width: 10px;
}

.background-masker.header-bottom {
    top: 18px;
    height: 6px;
}

.background-masker.subheader-left,
.background-masker.subheader-right {
    top: 24px;
    height: 6px;
}


.background-masker.header-right,
.background-masker.subheader-right {
    width: auto;
    left: 300px;
    right: 0;
}

.background-masker.subheader-right {
    left: 230px;
}

.background-masker.subheader-bottom {
    top: 30px;
    height: 10px;
}

.background-masker.content-top,
.background-masker.content-second-line,
.background-masker.content-third-line,
.background-masker.content-second-end,
.background-masker.content-third-end,
.background-masker.content-first-end {
    top: 40px;
    left: 0;
    right: 0;
    height: 6px;
}

.background-masker.content-top {
    height:20px;
}

.background-masker.content-first-end,
.background-masker.content-second-end,
.background-masker.content-third-end{
    width: auto;
    left: 380px;
    right: 0;
    top: 60px;
    height: 8px;
}

.background-masker.content-second-line  {
    top: 68px;
}

.background-masker.content-second-end {
    left: 420px;
    top: 74px;
}

.background-masker.content-third-line {
    top: 82px;
}

.background-masker.content-third-end {
    left: 300px;
    top: 88px;
}
<div class="timeline-wrapper">
    <div class="timeline-item">
        <div class="animated-background">
            <div class="background-masker header-top"></div>
            <div class="background-masker header-left"></div>
            <div class="background-masker header-right"></div>
            <div class="background-masker header-bottom"></div>
            <div class="background-masker subheader-left"></div>
            <div class="background-masker subheader-right"></div>
            <div class="background-masker subheader-bottom"></div>
            <div class="background-masker content-top"></div>
            <div class="background-masker content-first-end"></div>
            <div class="background-masker content-second-line"></div>
            <div class="background-masker content-second-end"></div>
            <div class="background-masker content-third-line"></div>
            <div class="background-masker content-third-end"></div>
        </div>
    </div>
</div>

关于javascript - 如何像预加载器一样实现 Youtube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69052308/

相关文章:

javascript - 带有改变颜色的动画省略号文本的 Chrome 错误。文本向右移动

javascript - 与 addEventListener 绑定(bind)

javascript - 如何阻止大于视口(viewport)的 DIV 滚动?

javascript - CSS 背景大小 : cover and background positioning for a 1000x100 graphic

html - 50% 高度的 div 堆叠成行

javascript - 基于函数式编程的 JavaScript 应用程序是如何布局的?

javascript - Canvas 周围不需要的边框

php - 如何使用外部 php 文件在不离开主 index.php 的情况下提交表单?

javascript - jQuery 在更新后使用当前数据

html - 从聚焦的只读输入中删除文本插入符号/指针