鼠标经过延迟时间 设置。。。

huangzehuanhuan 2012-07-17 08:20:58
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content

//On mouseover Event
$("ul.tabs li").mouseover(function() {

$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});

});
这段代码是控制 鼠标经过切换的,我想让延迟一下才切换(防止用户不经意的操作。。)谢谢啊
...全文
144 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
86y 2012-07-17
  • 打赏
  • 举报
回复

function Pause(obj,iMinSecond){
if (window.eventList==null) window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++){
if (window.eventList[i]==null) {
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1){
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
}

//js继续函数
function GoOn(ind){
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
}

$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content

//On mouseover Event
$("ul.tabs li").mouseover(function() {
Pause(this,2000);//2秒钟扣执行nextstep事件。。这样就可以设置下一个方法执行的开始时间
this.NextStep=function(){
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
}
});

});
gf05011 2012-07-17
  • 打赏
  • 举报
回复
不好意思,函数是这个setTimeout():

function test(){
alert($("#input1").val());
}
$(function(){
$("#input1").click(function(){
setTimeout("test()",1000);
});

});
86y 2012-07-17
  • 打赏
  • 举报
回复
可以的
javascript模拟sleep

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript模拟sleep http://www.ok22.org幸凡在线学习,网页设计,技术交流区,在线学习网,免费视频教程</title>
</head>
<body>
<script>
function Pause(obj,iMinSecond){
if (window.eventList==null) window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++){
if (window.eventList[i]==null) {
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1){
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
}

//js继续函数
function GoOn(ind){
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
}
function testJsStop(){ //调用方法
alert("1");
Pause(this,2000);//2秒钟扣执行nextstep事件。。这样就可以设置下一个方法执行的开始时间
this.NextStep=function(){
alert("2");
}
}
testJsStop();
</script>
</body>
</html>

huangzehuanhuan 2012-07-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

window.setInterval( function() {/*你的代码*/}, 1000);
[/Quote]你这里不行啊 你这里只是延迟加载 js而已 js加载完了 也一样不能实现鼠标经过延迟的效果啊
gf05011 2012-07-17
  • 打赏
  • 举报
回复
window.setInterval( function() {/*你的代码*/}, 1000);

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧