最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery adding style="overflow: hidden;" - Stack Overflow

programmeradmin1浏览0评论

I have created a bit of code to hide my menu, the menu is not complete but I am trying to use jQuery.slideUp() function but it adds style="overflow: hidden;" to the code so when I use .show one of my elements is hidden which is #nav:after and #nav:before which adds a small arrow to the bottom of the menu

here is the js code

  $("span#start_button").click(function () {
        if ($("#nav").is(":hidden")) {
            $("#nav").show("fast");
        } else {
            $("#nav").slideUp();
        }
    });

and here is the result on this site

How can I stop .slideUp() from creating style="overflow: hidden;" ?

I have created a bit of code to hide my menu, the menu is not complete but I am trying to use jQuery.slideUp() function but it adds style="overflow: hidden;" to the code so when I use .show one of my elements is hidden which is #nav:after and #nav:before which adds a small arrow to the bottom of the menu

here is the js code

  $("span#start_button").click(function () {
        if ($("#nav").is(":hidden")) {
            $("#nav").show("fast");
        } else {
            $("#nav").slideUp();
        }
    });

and here is the result on this site

How can I stop .slideUp() from creating style="overflow: hidden;" ?

Share Improve this question edited Dec 19, 2014 at 15:48 Kriem 8,70517 gold badges75 silver badges120 bronze badges asked Feb 1, 2013 at 12:48 LegendaryLaggyLegendaryLaggy 4551 gold badge6 silver badges16 bronze badges 2
  • 2 What do you want to do instead? If you want it to just slide up without disappearing you could use animate() instead. – gideon Commented Feb 1, 2013 at 12:52
  • look on the site, I dont want the arrow to disappear after using the .slideUp() function – LegendaryLaggy Commented Feb 1, 2013 at 12:56
Add a comment  | 

5 Answers 5

Reset to default 17

You must remove the overflow:hidden on the callback of the slideUp() function so you can try

$("#nav").slideUp('fast', function(){ $('#nav').css('overflow','visible') });

Or you can force it by css

#nav{overflow:visible!important}

This is bug in older jquery. This code replace standart function "slideDown" and delete overflow property.

!(function (jQuery, origSlideDown) {
jQuery.fn.slideDown = function (speed, easing, callback) {
    var self = this;
    var args = Array.prototype.slice.call(arguments);
    var origCallback;

    for (var i = 0, len = args.length; i < len; i++) {
        if (jQuery.isFunction(args[i])) {
            origCallback = args[i];
            args[i] = function () {
                origCallback.call(this);
                self.css('overflow', '');
            }
        }
    }

    if (!origCallback) {
        args.push(function () {
            self.css('overflow', '');
        });
    }

    return origSlideDown.apply(this, args);
};
})(jQuery, jQuery.fn.slideDown);

Override that style -

   $("#nav").slideUp();
   $("#nav").css({'overflow':'visible'});

Try this...

else {
   $("#nav").slideUp();
   $("#nav").css("overflow","visible");
}

Override the default styling by modifying the style attribute of html.

else {
       $("#nav").slideUp();
       $("#nav").attr("style","overflow:visible");
    }
发布评论

评论列表(0)

  1. 暂无评论