一個簡單的瀑布流效果(主體形式自寫)
更新時間:2013年05月27日 16:48:19 作者:
瀑布流的主體即為 幾個ul標(biāo)簽,新增加的元素以 li的形式按照當(dāng)前 ul的高度有選擇性的插入到某個ul下,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈
閑著沒事,自己寫了個瀑布流,我個人寫腳本或者是網(wǎng)頁的習(xí)慣是:只參考別人的效果,很少參考別人的代碼,有時侯我寧愿用審查元素來推斷代碼,也不愿去看源代碼。我不知道這個習(xí)慣好不好。雖然中間過程是花了我不少時間,但是我做的東西的每一個細(xì)節(jié)我都還能記清楚(當(dāng)然肯定后來會忘),因?yàn)槭俏覍?shí)現(xiàn)的。下面說正題:
瀑布流的主體即為幾個ul標(biāo)簽,新增加的元素以 li的形式按照當(dāng)前 ul的高度有選擇性的插入到某個ul下。
主體形式如下:
<div id="main">
<ul class="pics">
<li> <div class="pic"><img /></div> <div class="content">anytext..</div> </li>
<li><div class="pic"><img /></div> <div class="content">anytext..</div> </li>
...
</ul>
<ul class="pics"> <li> <div class="pic"><img /></div> <div class="content">anytext..</div> </li>
<li><div class="pic"><img /></div> <div class="content">anytext..</div> </li>
...
</ul>
....
</div>
css定義如下:
.pics {
float:left;
list-style:none;
margin-left:10px;
margin-right:10px;
width:230px;
}
.pics li {
display:block;
width:100%;
margin:0 auto;
margin-bottom:10px;
position:relative;
background-color:#FFF;
box-shadow: 0 1px 2px 0;
padding-top:10px;
}
.pic {
width:92%; margin:0 auto;
padding-top:10px;
text-align:center;
font-size:180px;
background-color:#0CF;
}
.pic img {
width:100%;
margin:0 auto;
}
.content {
width:92%;
margin:0 auto;
padding-top:10px;
height:50px;
text-overflow:ellipsis;
white-space:nowrap;
overflow:hidden;
}
腳本實(shí)現(xiàn)如下:
$(function(){
//alert($(window).height()); 瀏覽器當(dāng)前窗口可視區(qū)域高度
//alert($(document).height());
//瀏覽器當(dāng)前窗口文檔的高度 alert($(document.body).height());
//瀏覽器當(dāng)前窗口文檔body的高度 alert($(document.body).outerHeight(true));
//瀏覽器當(dāng)前窗口文檔body的總高度 包括border padding margin alert($(window).width());
//瀏覽器當(dāng)前窗口可視區(qū)域?qū)挾?alert($(document).width());
//瀏覽器當(dāng)前窗口文檔對象寬度 alert($(document.body).width());
//瀏覽器當(dāng)前窗口文檔body的高度 alert($(document.body).outerWidth(true));
//瀏覽器當(dāng)前窗口文檔body的總寬度 包括border padding margin
$(document).scroll(function(){
var pics=$(".pics");
var sc=$(document).scrollTop();
$("#float").text(sc);
for(var i=0;i<pics.length;i++){
var pic=pics.eq(i);
var bottom =pic.offset().top+pic.height();
if((sc+$(window).height())>=bottom){
eval( "var word=" + '"\\u' + (Math.round(Math.random() * 20901) + 19968).toString(16)+'"');
var li="<li> <div class='pic'>"+word+"</div><div class='content'>夢里過客笑眼望,望回廊,秋螽藏</div></li>";
pic.append(li);
}
}
});
});
這樣做基本實(shí)現(xiàn)了最簡單的一個瀑布流,但是腳本中并沒有考慮內(nèi)存消耗,即無限加載的問題?,F(xiàn)在我也沒搞懂,以后再完善吧 。
來看效果:
瀑布流的主體即為幾個ul標(biāo)簽,新增加的元素以 li的形式按照當(dāng)前 ul的高度有選擇性的插入到某個ul下。
主體形式如下:
復(fù)制代碼 代碼如下:
<div id="main">
<ul class="pics">
<li> <div class="pic"><img /></div> <div class="content">anytext..</div> </li>
<li><div class="pic"><img /></div> <div class="content">anytext..</div> </li>
...
</ul>
<ul class="pics"> <li> <div class="pic"><img /></div> <div class="content">anytext..</div> </li>
<li><div class="pic"><img /></div> <div class="content">anytext..</div> </li>
...
</ul>
....
</div>
css定義如下:
復(fù)制代碼 代碼如下:
.pics {
float:left;
list-style:none;
margin-left:10px;
margin-right:10px;
width:230px;
}
.pics li {
display:block;
width:100%;
margin:0 auto;
margin-bottom:10px;
position:relative;
background-color:#FFF;
box-shadow: 0 1px 2px 0;
padding-top:10px;
}
.pic {
width:92%; margin:0 auto;
padding-top:10px;
text-align:center;
font-size:180px;
background-color:#0CF;
}
.pic img {
width:100%;
margin:0 auto;
}
.content {
width:92%;
margin:0 auto;
padding-top:10px;
height:50px;
text-overflow:ellipsis;
white-space:nowrap;
overflow:hidden;
}
腳本實(shí)現(xiàn)如下:
復(fù)制代碼 代碼如下:
$(function(){
//alert($(window).height()); 瀏覽器當(dāng)前窗口可視區(qū)域高度
//alert($(document).height());
//瀏覽器當(dāng)前窗口文檔的高度 alert($(document.body).height());
//瀏覽器當(dāng)前窗口文檔body的高度 alert($(document.body).outerHeight(true));
//瀏覽器當(dāng)前窗口文檔body的總高度 包括border padding margin alert($(window).width());
//瀏覽器當(dāng)前窗口可視區(qū)域?qū)挾?alert($(document).width());
//瀏覽器當(dāng)前窗口文檔對象寬度 alert($(document.body).width());
//瀏覽器當(dāng)前窗口文檔body的高度 alert($(document.body).outerWidth(true));
//瀏覽器當(dāng)前窗口文檔body的總寬度 包括border padding margin
$(document).scroll(function(){
var pics=$(".pics");
var sc=$(document).scrollTop();
$("#float").text(sc);
for(var i=0;i<pics.length;i++){
var pic=pics.eq(i);
var bottom =pic.offset().top+pic.height();
if((sc+$(window).height())>=bottom){
eval( "var word=" + '"\\u' + (Math.round(Math.random() * 20901) + 19968).toString(16)+'"');
var li="<li> <div class='pic'>"+word+"</div><div class='content'>夢里過客笑眼望,望回廊,秋螽藏</div></li>";
pic.append(li);
}
}
});
});
這樣做基本實(shí)現(xiàn)了最簡單的一個瀑布流,但是腳本中并沒有考慮內(nèi)存消耗,即無限加載的問題?,F(xiàn)在我也沒搞懂,以后再完善吧 。
來看效果:
相關(guān)文章
jquery綁定原理 簡單解析與實(shí)現(xiàn)代碼分享
下面的內(nèi)容只是自己的一些理解,水平有限,難免有錯,望指正2011-09-09
淺析jQuery Ajax請求參數(shù)和返回數(shù)據(jù)的處理
這篇文章主要介紹了淺析jQuery Ajax請求參數(shù)和返回數(shù)據(jù)的處理的相關(guān)資料,需要的朋友可以參考下2016-02-02
淺析JQuery獲取和設(shè)置Select選項的常用方法總結(jié)
本篇文章是對JQuery獲取和設(shè)置Select選項的一些常用方法進(jìn)行了匯總介紹,有需要的朋友可以參考一下2013-07-07
jquery 模擬類搜索框自動完成搜索提示功能(改進(jìn))
改進(jìn)版,支持多個輸入框!前面因?yàn)槎鄠€輸入框信息不好保存所以只能支持一個,現(xiàn)在用輸入框的alt屬性來保存修改前的內(nèi)容,所以能支持多個輸入框了.初步測試沒發(fā)現(xiàn)問題,歡迎大家一起測試改進(jìn)!!!2010-05-05
jQuery采用連綴寫法實(shí)現(xiàn)的折疊菜單效果
這篇文章主要介紹了jQuery采用連綴寫法實(shí)現(xiàn)的折疊菜單效果,通過jQuery的連綴寫法(又稱鏈?zhǔn)讲僮?實(shí)現(xiàn)菜單折疊的顯示效果,非常簡單實(shí)用,需要的朋友可以參考下2015-09-09
jquery實(shí)現(xiàn)限制textarea輸入字?jǐn)?shù)的方法
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)限制textarea輸入字?jǐn)?shù)的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09

