Skip to content

Instantly share code, notes, and snippets.

@Rplus
Last active January 16, 2018 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Rplus/884b561e7a5d42249e02 to your computer and use it in GitHub Desktop.
Save Rplus/884b561e7a5d42249e02 to your computer and use it in GitHub Desktop.
Medium picture figure snippet
<figure name="322b" id="322b" class="graf--figure graf-after--h3">
<div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 389px;">
<div class="aspect-ratio-fill" style="padding-bottom: 55.60000000000001%;"></div>
<div class="progressiveMedia js-progressiveMedia graf-image"
data-image-id="1*vRzbJmu0VC5yWRWbc7d-0w.png"
data-width="955" data-height="531"
data-action="zoom" data-action-value="1*vRzbJmu0VC5yWRWbc7d-0w.png">
<img src="https://cdn-images-1.medium.com/freeze/max/33/1*vRzbJmu0VC5yWRWbc7d-0w.png?q=20"
crossorigin="anonymous" class="progressiveMedia-thumbnail js-progressiveMedia-thumbnail">
<canvas class="progressiveMedia-canvas js-progressiveMedia-canvas"></canvas>
<img class="progressiveMedia-image js-progressiveMedia-image"
data-src="https://cdn-images-1.medium.com/max/880/1*vRzbJmu0VC5yWRWbc7d-0w.png">
<noscript class="js-progressiveMedia-inner">
<img class="progressiveMedia-noscript js-progressiveMedia-inner" src="https://cdn-images-1.medium.com/max/880/1*vRzbJmu0VC5yWRWbc7d-0w.png">
</noscript>
</div>
</div>
<figcaption class="imageCaption">
The previous Salesforce1 style guide
</figcaption>
</figure>
@Rplus
Copy link
Author

Rplus commented Nov 8, 2015

.aspect-ratio-fillpadding-bottom 數值應該處理一下小數位數比較好,
一般來說兩三位應該就夠用了
這玩意主要就是把高度撐起來
因為後面主要呈現的圖樣區塊是用 position: absolute 處理的

原圖寬高在 server side 已經有給出了
雖然不確定是 server 動態算還是在上傳時就有記進去
總之這寬高比數值在處理 RWD image 是個關鍵點
不然頁面會跳來跳去的,很影響觀感
這值其實也可以丟給 <noscript> 裡的 img 寬高,但也不是必要就是了

接下來重點是 RWD image 的格式
class="progressiveMedia-thumbnail js-progressiveMedia-thumbnail" 這張是小圖
主要是拿來餵 <canvas>

真正大圖是有 data-src attribute 的圖片
等它 onload 後才算真的把圖載進來了

HTML 原始碼的部份大抵就是這樣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment