tab切换函数封装(mouseover、click)

基于jquery.js,对页面的tab切换进行封装,包含onmouseover以及click两种方法,js代码如下:

 1     function tab_down(tab_k, tab_con, tab_dz) {
 2         var $div_li = $(tab_k);
 3         var timeout
 4         if (tab_dz == "click") {
 5             $div_li.click(function() {
 6                 $(this).addClass("hover").siblings().removeClass("hover");
 7                 var index = $div_li.index(this);
 8                 $(tab_con).eq(index).show().siblings().hide();
 9             })
10         } else if (tab_dz == "mouseover") {
11             $div_li.hover(function() {
12                 var ts = $(this)
13                 timeout = setTimeout(function() {
14                     ts.addClass("hover").siblings().removeClass("hover");
15                     var index = ts.index();
16                     $(tab_con).eq(index).show().siblings().hide();
17                 }, 200)
18             }, function() {
19                 clearTimeout(timeout);
20             })
21         }
22 
23     }

代码引用简单事例如下:

//鼠标在ul>li上 mouseover的时候,ol>li对应的元素show()
tab_down
("ul>li", "ol>li", "mouseover");

 

posted @ 2017-03-06 14:40  W-road  阅读(1023)  评论(0编辑  收藏  举报