jQuery實(shí)現(xiàn)列表內(nèi)容的動(dòng)態(tài)載入特效
采用Jquery實(shí)現(xiàn)的列表數(shù)據(jù)動(dòng)態(tài)更新效果,更新的數(shù)據(jù)可以是ajax請(qǐng)求的數(shù)據(jù)。
CSS:
.main {
width: 100%;
margin-top: 100px;
text-align: center;
font-size: 12.5px;
}
th, td {
border: 1px solid #ccc;
line-height: 40px;
padding-left: 5px;
}
.item:hover {
background-color: #efefef;
}
.item:nth-child(2n) {
background-color: #efefef;
}
.ListView {
width: 600px;
overflow: hidden;
margin: 0 auto;
padding: 10px;
height:372px;
border: 1px solid #dddddd;
}
.ListView .c {
width: 1200px;
margin: 0 auto;
border-collapse: collapse;
}
.Item {
border-bottom: 1px dashed #dddddd;
padding: 10px 0 10px 0;
overflow: hidden;
margin-left:600px;
}
.Item span {
float: left;
text-align: left;
}
.Item span:first-child {
color: #6AA8E8;
}
.Item span:last-child {
text-align: center;
}
HTML
<div class="main"> <div class="ListView"> <div class="c"> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> <div class="Item"> <span>test</span> <span>男/0</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div> </div> </div> </div> <p style="text-align:center;"><a href="javascript:void(0);" onClick="ListView.Update();">刷新數(shù)據(jù)</a></p>
JS
<script type="text/javascript" src="/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(function(){
ListView.Init();
});
var ListView={
Init:function(){
$(".Item span").css("width",$(".ListView").width()/4+"px");
for(var i=0;i<$(".Item").length;i++){
var target=$(".Item")[i];
$(target).animate({marginLeft:"0px"},300+i*100);
}
},
Update:function(){
$(".ListView .c .Item").remove();
for(var i=0;i<10;i++){
var newItem=$("<div class=\"Item\"> <span>test</span> <span>男/"+i+"</span> <span>四川省,成都市,錦江區(qū)</span> <span>詳細(xì)說(shuō)明</span> </div>");
$(newItem).find("span").css("width",$(".ListView").width()/4+"px");
$(".ListView .c").append(newItem);
$(newItem).animate({marginLeft:"0px"},300+i*100);
}
}
}
</script>
附上演示效果 http://demo.jb51.net/js/2015/jquery-dtlb
效果是不是非常棒呢,接下來(lái)我們?cè)賮?lái)看看瀑布流的實(shí)現(xiàn)思路和js控制動(dòng)態(tài)加載的代碼
下面的代碼主要是控制滾動(dòng)條下拉時(shí)的加載事件的
在下面代碼說(shuō)明出,寫(xiě)上你的操作即可,無(wú)論是加載圖片還是加載記錄數(shù)據(jù) 都可以
別忘了引用jquery類庫(kù)
$(window).scroll(function () {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if (scrollTop + windowHeight == scrollHeight) {
//此處是滾動(dòng)條到底部時(shí)候觸發(fā)的事件,在這里寫(xiě)要加載的數(shù)據(jù),或者是拉動(dòng)滾動(dòng)條的操作
//var page = Number($("#redgiftNextPage").attr('currentpage')) + 1;
//redgiftList(page);
//$("#redgiftNextPage").attr('currentpage', page + 1);
}
});
解析:
判斷滾動(dòng)條到底部,需要用到DOM的三個(gè)屬性值,即scrollTop、clientHeight、scrollHeight。
scrollTop為滾動(dòng)條在Y軸上的滾動(dòng)距離。
clientHeight為內(nèi)容可視區(qū)域的高度。
scrollHeight為內(nèi)容可視區(qū)域的高度加上溢出(滾動(dòng))的距離。
從這個(gè)三個(gè)屬性的介紹就可以看出來(lái),滾動(dòng)條到底部的條件即為scrollTop + clientHeight == scrollHeight。(兼容不同的瀏覽器)。
- jQuery實(shí)現(xiàn)動(dòng)態(tài)顯示select下拉列表數(shù)據(jù)的方法
- jQuery實(shí)現(xiàn)動(dòng)態(tài)加載select下拉列表項(xiàng)功能示例
- 基于jQuery和Bootstrap框架實(shí)現(xiàn)仿知乎前端動(dòng)態(tài)列表效果
- jQuery動(dòng)態(tài)產(chǎn)生select option下拉列表
- jQuery簡(jiǎn)單實(shí)現(xiàn)向列表動(dòng)態(tài)添加新元素的方法示例
- jQuery實(shí)現(xiàn)動(dòng)態(tài)生成年月日級(jí)聯(lián)下拉列表示例
- 如何使用Jquery動(dòng)態(tài)生成二級(jí)選項(xiàng)列表
- jQuery列表動(dòng)態(tài)增加和刪除的實(shí)現(xiàn)方法
相關(guān)文章
uploadify 3.0 詳細(xì)使用說(shuō)明
uploadify 3.0 詳細(xì)使用說(shuō)明,需要的朋友可以參考下2012-06-06
jQuery實(shí)現(xiàn)網(wǎng)站添加高亮突出顯示效果的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)網(wǎng)站添加高亮突出顯示效果的方法,涉及jQuery針對(duì)頁(yè)面元素與樣式的操作技巧,需要的朋友可以參考下2015-06-06
使用jQuery判斷Div是否在可視區(qū)域的方法 判斷div是否可見(jiàn)
這篇文章主要介紹了使用jQuery判斷Div是否在可視區(qū)域的方法 判斷div是否可見(jiàn)2016-02-02
使用jquery實(shí)現(xiàn)仿百度自動(dòng)補(bǔ)全特效
這里給大家分享的效果是像百度的搜索框一樣,當(dāng)用戶在文本框輸入前幾個(gè)字母或是漢字的時(shí)候,該控件就能從存放數(shù)據(jù)的文或是數(shù)據(jù)庫(kù)里將所有以這些字母開(kāi)頭的數(shù)據(jù)提示給用戶,供用戶選擇,提供方便,增加用戶體驗(yàn)。2015-07-07

