近期Responsive web design項目經驗分享-高解析度圖片處理篇

來源:互聯網
上載者:User

標籤:des   class   blog   code   java   http   

在高解析度的情況下  商品的圖片難免會失真 

怎樣才能讓商品的圖片在高解析度的情況下 效果不失真 提供使用者更好的體驗呢 

我發現了一個解決方案 不知道是不是你想要的

先片對比下效果

 

左側是使用後     右側是使用前 

差距還是比較大的 

感興趣的小夥伴  可以下載源碼  自己嘗試一下 

https://github.com/scottjehl/picturefill

PICTUREFILL

The Web is truly worldwide, and we have to confront the fact that not everyone has access to fiberoptic connections and 4G networks. Scott Jehl encountered this digital divide first-hand while travelling and working his way through Southeast Asia, and he is a strong advocate of mobile-first and responsive websites that don’t put an undue burden on mobile users. His Picturefill script is a polyfill for the proposed <picture> element — JavaScript code that mimics the picture API, enabling us to use it on our websites today. The future is now, baby!

Picturefill does not require jQuery, but obviously it does require the picturefill.js script to be included somewhere in the page. Picturefill also requires some special markup, with divs to represent the image variations, differentiated by data-media attributes that act just like media queries in CSS. You may also optionally put an image in conditional comments for browsers that don’t support media queries (I’m looking at you, IE 8), and a fallback in a <noscript> tag for browsers that don’t have JavaScript enabled (I’m looking at you, BlackBerry).

Here’s an example of a typical Picturefill setup:

<span data-picture data-alt="Descriptive alt tag"> <span data-src="images/myimage_sm.jpg"></span> <span data-src="images/myimage_lg.jpg" data-media="(min-width: 600px)"></span> <!--[if (lt IE 10) & (!IEMobile)]> <span data-src="images/myimage_sm.jpg"></span> <![endif]--> <!-- Fallback content for non-JS browsers. --> <noscript> <img src="images/myimage_sm.jpg" alt="Descriptive alt tag" /> </noscript></span>

That’s all you need to display adaptive images at page-loading time using Picturefill. Drop in the script, configure the markup, and everything just works. You can also call Picturefill programmatically if you need to add images to the page on the fly.

Picturefill requires a lot of custom markup, so it might not be the best choice for those who cannot alter their website’s source code for any reason. It also doesn’t do any bandwidth detection. If bandwidth detection is important to your project, then have a look at this next solution.

 

An img with "srcset" and sizes" attributes:
<img sizes="(min-width: 40em) 80vw, 100vw"srcset="../examples/images/medium.jpg 375w, ../examples/images/medium.jpg 480w, ../examples/images/large.jpg 768w" alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia">

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.