功能较简单的jq tab选项卡

本文介绍了一个自定义的Tab插件,通过设置事件类型和自动切换功能,实现了Tab面板的无缝切换效果。代码示例展示了如何在页面加载时自动启动Tab切换,并通过触发事件手动切换。
(function ($) {
    //tab插件
    //可自定义事件
    $.fn.mytab = function (options) {
        var defaults = {
            tabContent:'.tabContent > li',
            type:'mouseenter',
            autotab:false, //自动切换
            callback:null
        };
        options = $.extend(defaults, options);
        var _this = $(this);
        var $tabConli = $(options.tabContent);
        var num = _this.length-1,
            count = 0,
            timer=null;
        function autoAnim(){
            timer=setTimeout(function(){
                count = (count == num) ? 0 : count + 1;
                _this.eq(count).trigger(options.type);
                setTimeout(arguments.callee,3000);
            },3000);
        }
        return this.each(function () {
            _this.bind(options.type,function () {
                clearTimeout(timer);
                $(this).addClass('on').siblings().removeClass('on');
                var index = _this.index(this);
                $tabConli.eq(index).stop(false,true).show(function(){
                    autoAnim();
                }).siblings().hide();
            }).eq(0).trigger(options.type);
            if (options.autotab) {
                autoAnim();
            }
        });

    };
})(jQuery);

$(document).ready(function () {
    $('.tabMenu > li').mytab({
        autotab:true
    });
});

  

转载于:https://www.cnblogs.com/webFrontDev/archive/2012/11/24/2786036.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值