jq选项卡鼠标延迟的插件实例
代码如下:
<!doctype html public "-//w3c//dtd html 4.01 transitional//en"
"http://www.w3.org/tr/html4/loose.dtd">
<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.7.min.js"></script>
<head>
<title>选项卡插件制作</title>
<style type="text/css">
*{margin: 0;padding: 0}
.tab{width: 350px;margin: 100px auto;}
.tabnav li{ list-style:none;cursor:pointer;float: left;width: 80px;border: 1px solid #ccc;border-radius: 5px;margin-right: 5px; height:24px;line-height: 24px;text-align: center;}
.tabnav li.cur{background:#daa520;}
.tabcontent{display: none;padding: 20px;}
.tabcon{border: 1px #708090 solid;background: #ffc0cb;height: 300px;clear: both;}
</style>
</head>
<script>
(function($){
$.fn.extend({
mytab:function(options){
var confings={
tabnav:'',//tab导航名称
tabtag:'',//tab导航标签
tabcon:'',//tab内容名称
contag:'',//tab内容标签和其他的类名
method: 'click'//鼠标事件状态
};//默认设置
options= $.extend(confings,options);
var that=$(this);
var tagnav=$(confings.tabnav);
var tabli=tagnav.find(confings.tabtag);
var tabcon=$(confings.tabcon);
var tabul=tabcon.find(confings.contag);
var timoutid=null;
tabli.each(function(ind){
$(this).bind(options.method,function(){
var linode = $(this);
timoutid = settimeout(function(){ //鼠标不小心划过的延迟时间
tabul.hide();
tabli.removeclass("cur");
tabul.eq(ind).show();
linode.addclass("cur");
},300);
}).mouut(function(){
cleartimeout(timoutid);
});
})
return this;
}
})
})(jquery);
$(function(){
$("#testtab5").mytab({
tabnav:"#tabtag5",tabtag:"li",tabcon:"#tabcon5",contag:".tabcontent",method:"mouseover"
});
$("#testtab").mytab({
tabnav:"#tabtag",tabtag:"li",tabcon:"#tabcon",contag:".tabcontent"
});
})
</script>
<body>
<p class="tab" id="testtab5">
<p class="tabnav" id="tabtag5">
<ul>
<li class="cur">菜单一</li>
<li>菜单二</li>
<li>菜单三</li>
</ul>
</p>
<p class="tabcon" id="tabcon5">
<p class="tabcontent" style="display: block;">内容一</p>
<p class="tabcontent">内容二</p>
<p class="tabcontent">内容三</p>
</p>
<p style="clear: both;margin-top: 60px;">
<p class="tab" id="testtab">
<p class="tabnav" id="tabtag">
<ul>
<li class="cur">菜单一</li>
<li>菜单二</li>
<li>菜单三</li>
</ul>
</p>
<p class="tabcon" id="tabcon">
<p class="tabcontent" style="display: block;">内容一</p>
<p class="tabcontent">内容二</p>
<p class="tabcontent">内容三</p>
</p>
</p>
</p>
</p>
</body>
</html>