国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

動(dòng)態(tài)標(biāo)簽 懸停效果 延遲加載示例代碼

2024-05-06 15:55:54
字體:
供稿:網(wǎng)友
懸停效果、延遲加載想必大家都有見到過吧,在本文將為大家介紹下是如何實(shí)現(xiàn)的,感興趣的朋友不要錯(cuò)過

----------------------對于動(dòng)態(tài)的標(biāo)簽綁定事件------------------------

復(fù)制代碼 代碼如下:


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 = "";//劃過某一字段傳的值
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)劃過就執(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);
}
});


----------------------------非動(dòng)態(tài)標(biāo)簽(查詢資料)-----------------------------------

復(fù)制代碼 代碼如下:


//hoverDuring 鼠標(biāo)經(jīng)過的延時(shí)時(shí)間
//outDuring 鼠標(biāo)移出的延時(shí)時(shí)間
//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為空時(shí),鼠標(biāo)移到字段顯示div,移出隱藏div
var that = $(this);
var id = that.attr("id");
var div = $("#tm");
div.css("position", "absolute");//讓這個(gè)層可以絕對定位
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)頁的寬
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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 安图县| 铜山县| 北辰区| 防城港市| 淳化县| 青海省| 阿勒泰市| 同德县| 鸡泽县| 云安县| 班玛县| 杭锦旗| 淮滨县| 鄯善县| 广河县| 六安市| 平和县| 东兰县| 蒲城县| 宜城市| 宁乡县| 泰和县| 深州市| 资阳市| 阳信县| 冷水江市| 婺源县| 明溪县| 汽车| 闻喜县| 靖远县| 孝昌县| 日喀则市| 临沧市| 阳高县| 虎林市| 新晃| 大安市| 临澧县| 珲春市| 泸定县|