jQuery+HTML5美女瀑布流布局實(shí)現(xiàn)方法
本文實(shí)例講述了jQuery+HTML5美女瀑布流布局實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:
這是一款JavaScript與HTML5實(shí)現(xiàn)美女瀑布流布局,本方法是把圖片的路徑寫在了JS的數(shù)組里,不過重點(diǎn)好像不是在這里,而是在圖片如何自動排列的問題,你可以運(yùn)行本實(shí)例后,點(diǎn)擊“加載瀑布流布局”按鈕,即可看到圖片的瀑布流排列效果,現(xiàn)在很流行這個(gè),希望您從本代碼中能找到一些靈感。
具體代碼如下:
<!DOCTYPE HTML> <html> <head> <title>美女瀑布流</title> <style type="text/css"> *{margin:0;padding:0} div.section{overflow:hidden} div.aside{width:225px;float:left;display:inline} div.aside div.content{margin:5px;background:#666} div.aside div.content img{width:205px;margin:5px;} div.aside div.content div.imgcaption{margin:0 5px;line-height:20px} </style> </head> <body> <div class="section"> <div class="aside"></div> <div class="aside"></div> <div class="aside"></div> <div class="aside"></div> </div> <button>加載瀑布流布局</button> </body> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> var json=[ {"text":"1","src":"images/1.jpg","height":"273"}, {"text":"2","src":"images/2.jpg","height":"273"}, {"text":"3","src":"images/3.jpg","height":"306"}, {"text":"4","src":"images/4.jpg","height":"270"}, {"text":"5","src":"images/5.jpg","height":"273"}, {"text":"6","src":"images/6.jpg","height":"307"}, {"text":"7","src":"images/7.jpg","height":"272"}, {"text":"8","src":"images/8.jpg","height":"285"}, {"text":"9","src":"images/9.jpg","height":"303"}, {"text":"10","src":"images/10.jpg","height":"272"}, {"text":"11","src":"images/5.jpg","height":"273"}, {"text":"12","src":"images/7.jpg","height":"273"}, {"text":"13","src":"images/3.jpg","height":"280"} ] function getSmallDiv(wrap,oD){ var len=oD.length; var h=Infinity; var getD; for(var i=0;i<len;i++){ if(oD.eq(i).height()<h){ h=oD.eq(i).height(); getD=oD.eq(i); } } return getD; } $("button").click(function(){ for(var i=0;i<json.length;i++){ var str; str="<div class=\"content\">"; str+="<img src="+json[i].src+" height="+json[i].height+" alt=\"\" />"; str+="<div class=\"imgcaption\">"+json[i].text+"</div>"; str+="</div>"; getSmallDiv($(".section"),$(".aside")).append(str); } }); </script> </html>
希望本文所述對大家的jQuery程序設(shè)計(jì)有所幫助。
相關(guān)文章
jQuery+json實(shí)現(xiàn)的簡易Ajax調(diào)用實(shí)例
這篇文章主要介紹了jQuery+json實(shí)現(xiàn)的簡易Ajax調(diào)用,結(jié)合實(shí)例形式分析了jQuery基于ajax實(shí)現(xiàn)json傳參調(diào)用的技巧,需要的朋友可以參考下2015-12-12一步一步教你寫一個(gè)jQuery的插件教程(Plugin)
我將會在下面的例子中一個(gè)一個(gè)的說明上面這幾個(gè)條件,做完這些事情后我們就會創(chuàng)建一個(gè)高亮顯示text的簡單插件。2009-09-09Visual Studio中的jQuery智能提示設(shè)置方法
Visual Studio中的jQuery智能提示設(shè)置方法,喜歡用vs2008開發(fā)的朋友可以參考下。2010-03-03jQuery實(shí)現(xiàn)圖片隨機(jī)切換、抽獎功能(實(shí)例代碼)
本文通過實(shí)例代碼給大家介紹了jQuery實(shí)現(xiàn)圖片隨機(jī)切換、抽獎功能,感興趣的朋友跟隨小編一起看看吧2019-10-10