javascript - Facebook 和媒体内容占位符样式

标签 javascript jquery user-interface

最近我注意到 Facebook 和 Medium 使用了延迟加载风格。然而,我发现 jQuery 或任何其他库都没有实现相同的风格。

有谁知道如何实现这一点,或者有任何熟悉的 jQuery 库可以做到这一点吗?

这是我所指的屏幕截图: Facebook and Medium style content loading

最佳答案

我刚刚在 Codepen 找到了一个:

	@-webkit-keyframes placeHolderShimmer {
	  0% {
	    background-position: -468px 0
	  }
	  100% {
	    background-position: 468px 0
	  }
	}
	
	@keyframes placeHolderShimmer {
	  0% {
	    background-position: -468px 0
	  }
	  100% {
	    background-position: 468px 0
	  }
	}
	
	.timeline-wrapper {
	  background-color: #e9eaed;
	  color: #141823;
	  padding: 20px;
	  border: 1px solid #ccc;
	}
	
	.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;
	}
	
	.animated-background {
	  -webkit-animation-duration: 1s;
	  animation-duration: 1s;
	  -webkit-animation-fill-mode: forwards;
	  animation-fill-mode: forwards;
	  -webkit-animation-iteration-count: infinite;
	  animation-iteration-count: infinite;
	  -webkit-animation-name: placeHolderShimmer;
	  animation-name: placeHolderShimmer;
	  -webkit-animation-timing-function: linear;
	  animation-timing-function: linear;
	  background: #f6f7f8;
	  background: #eeeeee;
	  background: -webkit-gradient(linear, left top, right top, color-stop(8%, #eeeeee), color-stop(18%, #dddddd), color-stop(33%, #eeeeee));
	  background: -webkit-linear-gradient(left, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
	  background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
	  -webkit-background-size: 800px 104px;
	  background-size: 800px 104px;
	  height: 96px;
	  position: relative;
	}
	
	.background-masker {
	  background: #fff;
	  position: absolute;
	  -webkit-box-sizing: border-box;
	  -moz-box-sizing: border-box;
	  box-sizing: border-box;
	}
	
	.outlined .background-masker {
	  border: 1px solid #ddd;
	}
	
	.outlined:hover .background-masker {
	  border: none;
	}
	
	.outlined:hover .background-masker:hover {
	  border: 1px solid #ccc;
	  z-index: 1;
	}
	
	.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 facebook">
      <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 - Facebook 和媒体内容占位符样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35119177/

相关文章:

java - 检查(多个 Jbutton 中的)哪个 Jbutton 被单击

Javascript 从子页面回发父页面

javascript - 在没有数据库的情况下更新 html 'permanenlty'?

java - 为什么 BoxLayout 不允许我更改 JButton 的宽度但让我更改高度?

jquery - 通过 HTTPS 上传时,为什么我在 IE8/IE9 上从 plupload 收到 "Security Error"?

javascript - 如何检查选择了哪个单选按钮并在 jQuery 中使用 if else 语句应用适当的行为

.net - 从 .NET 中的另一个线程更改 UI 元素

javascript - 克隆对象和函数内部引用

c# - 将值从 View 传递到 Controller - MVC

javascript - jQuery 重新加载 xml 文档需要关闭浏览器吗?