简体   繁体   中英

Jquery slide tab from right to left function

I am currently trying to slide a tab from right to left using this code but i am not achieving my initial goal. this is the jquery file. I tried implementing animate direction left but it only gave me errors.

(function ($) {
    $.fn.showHide = function (options) {
        //default vars for the plugin
        var defaults = {
            speed: 1000,
            easing: '',
            changeText: 0,
            showText: 'Show',
            hideText: 'Hide'
        };
        var options = $.extend(defaults, options);

        $(this).click(function () { 

            $('.toggleDiv').slideUp(options.speed, options.easing); 

            var toggleClick = $(this);

            var toggleDiv = $(this).attr('rel');

            $(toggleDiv).slideToggle(options.speed, options.easing, function() {

                if(options.changeText==1){
                    $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
                }
            });

            return false;

        });

    };
})(jQuery);

Main problem here:

var options = $.extend(defaults, options);

You're declaring options twice, in the function as a parameter, and as a variable inside the function. This is a source of problems. Just rename it to opts for example:

var opts = $.extend(defaults, options);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM