日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

仿百度图片自适应

發(fā)布時(shí)間:2024/4/14 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 仿百度图片自适应 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

其實(shí)這個(gè)實(shí)例來(lái)自http://www.w3cfuns.com/blog-5400161-5394900.html

我只是稍微改了一下,覺(jué)得這個(gè)功能還是很實(shí)用的。

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>無(wú)標(biāo)題文檔</title> 6 <style type="text/css"> 7 .box { width:200px; height:200px; padding:10px; float:left; text-align:center; border:#ddd solid 1px; margin-right:20px; } 8 </style> 9 </head> 10 <body> 11 <div id="imgList"> 12 <div class="box"><img src="images/oldman.jpg" /></div> 13 <div class="box"><img src="images/lovers.jpg" /></div> 14 <div class="box"><img src="images/girl.jpg" /></div> 15 </div> 16 <script type="text/javascript"> 17 var maxWidth = 200, 18 maxHeight = 200, 19 imgs = document.getElementById("imgList").getElementsByTagName("img"); 20 for(var i=0; i<imgs.length; i++) { 21 imgs[i].onload = fixImg; 22 } 23 function fixImg() { 24 var image = new Image(); 25 image.src = this.src; 26 if(image.width>0 && image.height>0) { 27 var rate = (maxWidth/image.width < maxHeight/image.height)?maxWidth/image.width:maxHeight/image.height; 28 if(rate<=1) { 29 this.width = image.width*rate; 30 this.height = image.height*rate; 31 } 32 else { 33 this.width = image.width; 34 this.height = image.height; 35 } 36 } 37 } 38 </script> 39 </body> 40 </html>

轉(zhuǎn)載于:https://www.cnblogs.com/ecren/archive/2012/05/14/2499148.html

總結(jié)

以上是生活随笔為你收集整理的仿百度图片自适应的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。