- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 140字
- 2021-07-08 10:04:07
Using responsive images and srcset to deliver high quality images on all screen sizes
To achieve the second goal, we can use layout="responsive" again, so that the thumbnails will scale for larger screens. The HTML for each item in the list now looks like this:
<li>
<figure class="related-thumb">
<amp-img src="img/penguin.jpg" width="125" height="75" layout="responsive"></amp-img>
<figcaption>
If a penguin can find a soul mate, I'm sure I can too
<span class="author">Rebekah Crane</span>
</figcaption>
</figure>
</li>

Thumbnails in 2x2 grid and with layout="responsive" scaling up on a larger screen (tablet device in portrait orientation)
There is a problem with this solution, however. It's the same problem that we had earlier when our main feature image was scaled up on large screens: it became pixelated. The same thing will happen with our thumbnails. Thankfully, we can apply the same solution as before using srcset:
<amp-img src="penguin.jpg"
srcset="img/penguin-sm.jpg 125w,
img/penguin.jpg 640w"
width="125"
height="75"
layout="responsive"
</amp-img>
Now, on larger screens, the browser will automatically use the higher resolution image.
推薦閱讀
- Java 開發從入門到精通(第2版)
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- Mastering Articulate Storyline
- 編程珠璣(續)
- The Data Visualization Workshop
- PHP 7+MySQL 8動態網站開發從入門到精通(視頻教學版)
- Test-Driven Development with Django
- MySQL入門很輕松(微課超值版)
- Regression Analysis with Python
- RubyMotion iOS Develoment Essentials
- 零基礎學C語言(第4版)
- Android應用開發實戰(第2版)
- MySQL數據庫應用實戰教程(慕課版)
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)
- 快樂編程:青少年思維訓練