开发者社区> 问答> 正文

关于JQ TABS的问题!

前辈们晚上好,小弟第一次用JQ写代码,但是出了点问题,自己不太理解,望前辈们不吝赐教
我写了一个自动的TABS,但mouseout部分无法正常运作。只有mouseover有效果。
screenshot然后画圈的两个,为什么只能写在mouseover 跟 mouseout里面?写在外面会没有效果?
screenshot
screenshot这是我去掉for循环之后,但是还是不执行,也不报错

展开
收起
小旋风柴进 2016-05-31 10:46:53 2066 0
1 条回答
写回答
取消 提交回答
  • 这有必要用for循环吗,把for循环去掉先

    更新:

    $(document).ready(function () {
    
        var $lis = $("#t-hd").find("li");
        var $divs = $("#t-bd").find("div");
        var lisLength = $lis.length;
        var timer = 0;
        var intervalInit = 0;
    
        $lis.mouseover(function () {
            clearInterval(timer);
            $(this).addClass("hd-active").siblings().removeClass("hd-active");
            var index = $(this).index();
            $divs.hide();
            $divs.eq(index).show();
        }).mouseout(function () {
            timer = 0;
            var that = this;
            timer = setTimeout(function () {
                var index = $(that).index();
                if (index >= lisLength) {
                    index = 0;
                }
                $(that).addClass("hd-active").siblings().removeClass("hd-active");
                $divs.hide().eq(index).show();
            }, 2000);
        });
        timer = setInterval(function () {
            intervalInit = intervalInit % lisLength;
            $(this).addClass("hd-active").siblings().removeClass("hd-active");
            $divs.hide().eq(intervalInit).show();
            intervalInit++;
        }, 2000);
    2019-07-17 19:21:31
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载