jquery中hover鼠标一经过指定元素就起作用想让鼠标在指定元素上停留几秒钟,再弹出div怎么实现谢谢
解决方案 »
- parentWindow到底是什么意思?
- 内存不断增加,麻烦给优化一下代码.Thx
- js如何获取listviw某列中的服务器控件的值?
- 谁能给我举出几个js代码在web开发中的作用
- new ActiveXObject("Msxml2.DOMDocument");
- 请教关于IE、firefox、chrome以及opera等不同浏览器的iframe的高度兼容问题
- javascript正则表达式的的标识问题
- 请大虾指教窗口关闭问题?
- 请问怎样向一个txt文件的最后添加新行,谢谢?
- 一个列表框,里面是文件的名字,怎么样一点一个项,就打开一个相应网页呀。必给分!!!!!
- 求JS倒计时脚本!输入日期得到天数
- JQUERY
<!doctype html>
<html>
<head>
<meta charset="gb2312" />
<style>
#box {
width:100px; height:100px; border:1px solid red; display:none;
}
</style>
</head>
<body>
<div id="test">测试</div>
<div id="box"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script>
$('#test').mouseover(function(){
$('#box').delay(1000).slideDown()
})
</script>
</body>
</html>
楼主试试。
不对啊 ,代码虽然是等1秒后弹出div但不是鼠标一直指在test上才触发事件而是只要鼠标指上去,1秒后就睡触发
如何在settimeout里添加显示div的代码
settimeout("fn()",1000);
})
function fn(){
$("#div").css("display","block");
}
举个例子吧比如:
<div id="hover">hover</div>
<div id="display">display</div>如何让鼠标在hover上停留一秒钟再显示display
鼠标离开hover一秒钟再隐藏display求代码解释谢谢
$(function(){
var over,out;
$("#hover").mouseover(function(){
var display = $("#display");
if(display.css("display") == "none"){
over = window.setTimeout(function(){
display.show();
},1000);
}
clearTimeout(out);
}).mouseout(function(){
var display = $("#display");
if(display.css("display") == "block"){
out = window.setTimeout(function(){
display.hide();
},1000);
}
clearTimeout(over);
});
});
$('#test').mouseover(function(){
var showHandler = setTimeout(function(){$('#box').show();} ,1000*1);
}).mouseout(function(){
if(showHandler){clearTimeout(showHandler);}
$('#box').hide();
});补充1楼的js
那个,,厚着脸皮问一句怎么把它应用到html上
好用了那个,这两句clearTimeout(out);
clearTimeout(over);这两句有什么用
$('#test').mouseover(function(){
begin =setTimeout("fn()",1000);
})
function fn(){
clearTimeout(begin);
}这个是jquery的写法,意思跟大家的差不多了。。mouseover的时候开启setTimeout,一旦离开的时候马上关闭。如果时间超过1秒那么自动执行fn()
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#box {
width:100px; height:100px; border:1px solid red; display:none;
}
</style>
</head>
<body>
<div id="test">测试</div>
<div id="box">鼠标已停留1秒钟</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script>
var timer;
$('#test').mouseover(function(){
var elem = $(this);
timer = setTimeout(function(){
$('#box').show();
}, 1000);
});
$('#test').mouseout(function(){
clearTimeout(timer);
});
</script>
</body>
</html>