动态标签 悬停效果 延迟加载示例代码
复制代码 代码如下:
var outTimer;//执行时间
var upTimer;//执行时间
var sqDiv = $("#tm");//要显示的div
var test="";//标识,为了将鼠标移到显示的div上时,div不会消失
var dd = "";//划过某一字段传的值
function test1(){
$("#tm").empty();//现将div清空
$.ajax({ //往里加数据
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) { //给动态标签绑定事件
if(event.type=='mouseover'){ //移上时
clearTimeout(outTimer);//先清空移出的时间,这样能避免鼠标划过就执行函数,减轻服务器的压力
dd=$(this).attr("id");
upTimer = setTimeout(test1, 500);//0.5秒后再执行
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//说明鼠标在显示的div上
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
----------------------------非动态标签(查询资料)-----------------------------------
复制代码 代码如下:
//hoverDuring 鼠标经过的延时时间
//outDuring 鼠标移出的延时时间
//hoverEvent 鼠标经过执行的方法
//outEvent 鼠标移出执行的方法
$( 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();//获取网页的宽
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();
}
}
});
});
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/shell/11882.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Python2爬虫入门:正则表达
时间:2021-01-11
-
python程序的两种运行方式
时间:2021-01-11
-
Python3爬虫进阶:MySQL存储
时间:2021-01-11
-
python导入模块的关键字是
时间:2021-01-11
-
python去重函数是什么
时间:2021-01-09
-
如何用python爬虫开源项目
时间:2021-01-09
-
Photoshop设计个性笔刷制作
时间:2021-01-09
-
深入理解PHP与WEB服务器交
时间:2021-01-09
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
php如何接收json数据
时间:2021-01-08
-
php ucwords函数怎么用
时间:2021-01-08
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
python中pow什么意思
时间:2021-01-08
-
如何在python数据挖掘使用pandas包?
时间:2021-01-09
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
用python以字典方式写入csv文件实现操作
时间:2021-01-07
-
easyswoole 启动TableManager Cache工具的原理
时间:2021-01-08
