動態(tài)標(biāo)簽 懸停效果 延遲加載示例代碼
更新時間:2013年11月21日 15:19:19 作者:
懸停效果、延遲加載想必大家都有見到過吧,在本文將為大家介紹下是如何實現(xiàn)的,感興趣的朋友不要錯過
----------------------對于動態(tài)的標(biāo)簽綁定事件------------------------
var outTimer;//執(zhí)行時間
var upTimer;//執(zhí)行時間
var sqDiv = $("#tm");//要顯示的div
var test="";//標(biāo)識,為了將鼠標(biāo)移到顯示的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)標(biāo)簽綁定事件
if(event.type=='mouseover'){ //移上時
clearTimeout(outTimer);//先清空移出的時間,這樣能避免鼠標(biāo)劃過就執(zhí)行函數(shù),減輕服務(wù)器的壓力
dd=$(this).attr("id");
upTimer = setTimeout(test1, 500);//0.5秒后再執(zhí)行
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//說明鼠標(biāo)在顯示的div上
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
----------------------------非動態(tài)標(biāo)簽(查詢資料)-----------------------------------
//hoverDuring 鼠標(biāo)經(jīng)過的延時時間
//outDuring 鼠標(biāo)移出的延時時間
//hoverEvent 鼠標(biāo)經(jīng)過執(zhí)行的方法
//outEvent 鼠標(biāo)移出執(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 = "";//當(dāng)test為空時,鼠標(biāo)移到字段顯示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();
}
}
});
});
復(fù)制代碼 代碼如下:
var outTimer;//執(zhí)行時間
var upTimer;//執(zhí)行時間
var sqDiv = $("#tm");//要顯示的div
var test="";//標(biāo)識,為了將鼠標(biāo)移到顯示的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)標(biāo)簽綁定事件
if(event.type=='mouseover'){ //移上時
clearTimeout(outTimer);//先清空移出的時間,這樣能避免鼠標(biāo)劃過就執(zhí)行函數(shù),減輕服務(wù)器的壓力
dd=$(this).attr("id");
upTimer = setTimeout(test1, 500);//0.5秒后再執(zhí)行
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//說明鼠標(biāo)在顯示的div上
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
----------------------------非動態(tài)標(biāo)簽(查詢資料)-----------------------------------
復(fù)制代碼 代碼如下:
//hoverDuring 鼠標(biāo)經(jīng)過的延時時間
//outDuring 鼠標(biāo)移出的延時時間
//hoverEvent 鼠標(biāo)經(jīng)過執(zhí)行的方法
//outEvent 鼠標(biāo)移出執(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);
});
});
}
復(fù)制代碼 代碼如下:
//$("#sosoFod h3").each( function() {
$("#sosoweb").each( function() {
var test = "";//當(dāng)test為空時,鼠標(biāo)移到字段顯示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)文章
js調(diào)用iframe實現(xiàn)打印頁面內(nèi)容的方法
這篇文章主要介紹了js調(diào)用iframe實現(xiàn)打印頁面內(nèi)容的方法,需要的朋友可以參考下2014-03-03
基于jquery鼠標(biāo)點擊其它地方隱藏層的實例代碼
基于jquery鼠標(biāo)點擊其它地方隱藏層的實例代碼,需要的朋友可以參考下。2011-01-01
jQuery模仿ToDoList實現(xiàn)簡單的待辦事項列表
這篇文章主要介紹了jQuery模仿ToDoList實現(xiàn)簡單的待辦事項列表,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
jQuery實現(xiàn)帶滾動導(dǎo)航效果的全屏滾動相冊實例
這篇文章主要介紹了jQuery實現(xiàn)帶滾動導(dǎo)航效果的全屏滾動相冊,涉及jQuery針對頁面圖片元素與鼠標(biāo)事件的相關(guān)操作技巧,需要的朋友可以參考下2015-06-06
關(guān)于Jquery操作Cookie取值錯誤的解決方法
使用JQuery操作cookie時 發(fā)生取的值不正確,結(jié)果發(fā)現(xiàn)cookie有四個不同的屬性,下面與大家分享下錯誤的原因及解決方法2013-08-08
jquery如何判斷表格同一列不同行input數(shù)據(jù)是否重復(fù)
這篇文章主要介紹了jquery如何判斷表格同一列不同行input數(shù)據(jù)是否重復(fù),需要的朋友可以參考下2014-05-05
jQuery防止click雙擊多次提交及傳遞動態(tài)函數(shù)或多參數(shù)
這篇文章主要介紹了jQuery防止click雙擊多次提交及傳遞動態(tài)函數(shù)方法,需要的朋友可以參考下2014-04-04
google jQuery 引用文件,jQuery 引用地址集合(jquery 1.2.6至jquery1.5.2)
很多網(wǎng)站都是使用這種方式引入,客戶的瀏覽器可能已經(jīng)緩存過了 jquery??梢灾苯诱{(diào)用本地的,速度更快2011-04-04

