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

