
這jquery plugin可以幫助你的用戶自動根據自己的連接速度來選擇合適的圖片質素。當然,現在的連接速度是很快,可是你的用戶當中,肯定有些仍然是用比較慢的連線。比如說這人是用手機gprs上網,或是他的網絡同一時間有太多人使用,都會做成連線過慢的。如果這時候,你的網頁還有有很多size很大,resolution很高的圖片,比如一幅是幾百KB,或超過1MB的,用戶肯定會馬上離開,即使有很好的內容也留不住他。
這plugin通過ajax,做個很小的speed test,如果太慢的話(自己定一個threshold value),就顯示質素比較低的圖片。由於這speed test只花費很少,對高速連線根本沒有任何負擔,對低速連線就可以省掉後來負擔過大的圖片下載。
直接點說這plugin就是幫你選圖片,你要有高質素圖片(*_h.jpg),和相應的低質素圖片(*_l.jpg)。請參考demo的做法。
Download: jquery.MyPicResolutionSelector.js
Demo: MyPicResolutionSelector
License: MIT License
Html code:
jQuery Code:
//IMPORTANT: just after the above html code, call the plugins in a script block
// If you put it in head, some browser may not run properly
//PARAMETERS
//slowThreshold: threshold for selection in millisecond
(larger value allow much slower connection to show hi resolution images)
//testFile: 4KB dummy file to determine the speed of connection
//bAlwaysLowRes: always load low resolution flag for debug
$("#imglist img").MySelectPicResolution({
slowThreshold:500,
testFile: "4kb.txt",
bAlwaysLowRes: false
});
//OR
$("#imglist img").MySelectPicResolution();