Skip to content

Instantly share code, notes, and snippets.

@letswritetw
Created August 2, 2018 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letswritetw/1fc830f2d3537ebe048eb4165f785b70 to your computer and use it in GitHub Desktop.
Save letswritetw/1fc830f2d3537ebe048eb4165f785b70 to your computer and use it in GitHub Desktop.
像Medium的漸近式圖片加載
.lazy-image
text-align: center
// img 先把透明度調成 0,才有淡入的效果
img
opacity: 0
transition: opacity 1s linear
// 將區塊等比例撐開
.small
width: 100%
height: 0
background-size: cover
background-position: center center
// 圖片淡入
&.show img
opacity: 1
// 16:9
&.w16-9 .small
padding-bottom: 56.25%
// 4:3
&.w4-3 .small
padding-bottom: 75%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment