動態(tài)標簽 懸停效果 延遲加載示例代碼
更新時間:2013年11月21日 15:19:19 作者:
懸停效果、延遲加載想必大家都有見到過吧,在本文將為大家介紹下是如何實現(xiàn)的,感興趣的朋友不要錯過
----------------------對于動態(tài)的標簽綁定事件------------------------
var outTimer;//執(zhí)行時間
var upTimer;//執(zhí)行時間
var sqDiv = $("#tm");//要顯示的div
var test="";//標識,為了將鼠標移到顯示的div上時,div不會消失
var dd = "";//劃過某一字段傳的值
function test1(){
$("#tm").empty();//現(xiàn)將div清空
$.ajax({ //往里加數(shù)據(jù)
type:"post",
url:"<%=path %>/webmodule/constructionDecision/BaseCD/getCommunityInfo.do?stCode="+dd,
dataType:"json",
async:false,
success:function(data){
var td="";
for(var i=0;i<data.length;i++){
td+="<a id ='"+data[i].gridNumber+"'>"+data[i].name+"</a>";
}
$("#tm").append(td);
}
});
$("#tm").show();
}
function test2(){//隱藏div的方法
if(test ==""){
$("#tm").hide();
}
}
$("#cityTable a").die().live('mouseover mouseout', function(event) { //給動態(tài)標簽綁定事件
if(event.type=='mouseover'){ //移上時
clearTimeout(outTimer);//先清空移出的時間,這樣能避免鼠標劃過就執(zhí)行函數(shù),減輕服務(wù)器的壓力
dd=$(this).attr("id");
upTimer = setTimeout(test1, 500);//0.5秒后再執(zhí)行
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//說明鼠標在顯示的div上
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
----------------------------非動態(tài)標簽(查詢資料)-----------------------------------
//hoverDuring 鼠標經(jīng)過的延時時間
//outDuring 鼠標移出的延時時間
//hoverEvent 鼠標經(jīng)過執(zhí)行的方法
//outEvent 鼠標移出執(zhí)行的方法
$( function() {
$.fn.hoverDelay = function(options) {
var defaults = {
hoverDuring :200,
outDuring :200,
hoverEvent : function() {
$.noop();
},
outEvent : function() {
$.noop();
}
};
var sets = $.extend(defaults, options || {});
var hoverTimer, outTimer;
return $(this).each( function() {
$(this).hover( function() {
clearTimeout(outTimer);
hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
}, function() {
clearTimeout(hoverTimer);
outTimer = setTimeout(sets.outEvent, sets.outDuring);
});
});
}
//$("#sosoFod h3").each( function() {
$("#sosoweb").each( function() {
var test = "";//當test為空時,鼠標移到字段顯示div,移出隱藏div
var that = $(this);
var id = that.attr("id");
var div = $("#tm");
div.css("position", "absolute");//讓這個層可以絕對定位
that.hoverDelay( {
outDuring :1000,
hoverEvent : function() {
div.css("display", "block");
var p = that.position(); //獲取這個元素的left和top
var x = p.left + that.width();//獲取這個浮動層的left
var docWidth = $(document).width();//獲取網(wǎng)頁的寬
if (x > docWidth - div.width() - 20) {
x = p.left - div.width();
}
div.css("left", x);
div.css("top", p.top);
//$("#tm").show();
},
outEvent : function() {
$("#tm").hoverDelay( {
outDuring :1000,
hoverEvent : function() {
test = "on";
$("#tm").show();
},
outEvent : function() {
test="";
$("#tm").hide();
}
});
if(test==""){
$("#tm").hide();
}
}
});
});
復制代碼 代碼如下:
var outTimer;//執(zhí)行時間
var upTimer;//執(zhí)行時間
var sqDiv = $("#tm");//要顯示的div
var test="";//標識,為了將鼠標移到顯示的div上時,div不會消失
var dd = "";//劃過某一字段傳的值
function test1(){
$("#tm").empty();//現(xiàn)將div清空
$.ajax({ //往里加數(shù)據(jù)
type:"post",
url:"<%=path %>/webmodule/constructionDecision/BaseCD/getCommunityInfo.do?stCode="+dd,
dataType:"json",
async:false,
success:function(data){
var td="";
for(var i=0;i<data.length;i++){
td+="<a id ='"+data[i].gridNumber+"'>"+data[i].name+"</a>";
}
$("#tm").append(td);
}
});
$("#tm").show();
}
function test2(){//隱藏div的方法
if(test ==""){
$("#tm").hide();
}
}
$("#cityTable a").die().live('mouseover mouseout', function(event) { //給動態(tài)標簽綁定事件
if(event.type=='mouseover'){ //移上時
clearTimeout(outTimer);//先清空移出的時間,這樣能避免鼠標劃過就執(zhí)行函數(shù),減輕服務(wù)器的壓力
dd=$(this).attr("id");
upTimer = setTimeout(test1, 500);//0.5秒后再執(zhí)行
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//說明鼠標在顯示的div上
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
----------------------------非動態(tài)標簽(查詢資料)-----------------------------------
復制代碼 代碼如下:
//hoverDuring 鼠標經(jīng)過的延時時間
//outDuring 鼠標移出的延時時間
//hoverEvent 鼠標經(jīng)過執(zhí)行的方法
//outEvent 鼠標移出執(zhí)行的方法
$( function() {
$.fn.hoverDelay = function(options) {
var defaults = {
hoverDuring :200,
outDuring :200,
hoverEvent : function() {
$.noop();
},
outEvent : function() {
$.noop();
}
};
var sets = $.extend(defaults, options || {});
var hoverTimer, outTimer;
return $(this).each( function() {
$(this).hover( function() {
clearTimeout(outTimer);
hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
}, function() {
clearTimeout(hoverTimer);
outTimer = setTimeout(sets.outEvent, sets.outDuring);
});
});
}
復制代碼 代碼如下:
//$("#sosoFod h3").each( function() {
$("#sosoweb").each( function() {
var test = "";//當test為空時,鼠標移到字段顯示div,移出隱藏div
var that = $(this);
var id = that.attr("id");
var div = $("#tm");
div.css("position", "absolute");//讓這個層可以絕對定位
that.hoverDelay( {
outDuring :1000,
hoverEvent : function() {
div.css("display", "block");
var p = that.position(); //獲取這個元素的left和top
var x = p.left + that.width();//獲取這個浮動層的left
var docWidth = $(document).width();//獲取網(wǎng)頁的寬
if (x > docWidth - div.width() - 20) {
x = p.left - div.width();
}
div.css("left", x);
div.css("top", p.top);
//$("#tm").show();
},
outEvent : function() {
$("#tm").hoverDelay( {
outDuring :1000,
hoverEvent : function() {
test = "on";
$("#tm").show();
},
outEvent : function() {
test="";
$("#tm").hide();
}
});
if(test==""){
$("#tm").hide();
}
}
});
});
相關(guān)文章
Tab頁界面 用jQuery及Ajax技術(shù)實現(xiàn)(php后臺)
到了B/S開發(fā)時代,網(wǎng)頁前端布局也把Tab頁的布局形式吸收了過來。特別是和Ajax技術(shù)結(jié)合起來,可以更充分發(fā)揮Tab頁的良好表現(xiàn)力和數(shù)據(jù)緩存的優(yōu)勢,是一種良好的網(wǎng)頁布局形式2011-10-10jQuery基于ajax實現(xiàn)頁面加載后檢查用戶登錄狀態(tài)的方法
這篇文章主要介紹了jQuery基于ajax實現(xiàn)頁面加載后檢查用戶登錄狀態(tài)的方法,結(jié)合實例形式較為詳細分析了jQuery結(jié)合ajax進行表單登陸驗證操作的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-02-02jQuery.extend()、jQuery.fn.extend()擴展方法示例詳解
這篇文章主要介紹了jQuery.extend()、jQuery.fn.extend()擴展方法的應用,需要的朋友可以參考下2014-05-05jQuery模擬原生態(tài)App上拉刷新下拉加載更多頁面及原理
很多App中,新聞或者展示類都存在下拉刷新和上拉加載的效果,如何實現(xiàn)上拉刷新下拉加載更多頁面的呢?下面小編通過下面內(nèi)容給大家介紹jQuery模擬原生態(tài)App上拉刷新下拉加載更多頁面及原理,需要的朋友可以參考下2015-08-08