jQuery slideToggle jumps around

前端 未结 18 1291
迷失自我
迷失自我 2020-12-16 18:13

I\'m using the jQuery slideToggle function on a site to reveal \'more information\' about something. When I trigger the slide, the content is gradually revealed, but is loc

相关标签:
18条回答
  • 2020-12-16 19:08

    I have found a workaround, but I'm still not sure of the details. It seemed that when the 'overflow: hidden' style was added by jQuery, the effect that a nearby floated element had changed. The workaround was to place a permanent 'overflow: hidden' on the slideToggle'd div, and also a negative margin-left to counterbalance the effect.

    I am surprised that changing the overflow value has such an effect on layout, but there you have it...

    0 讨论(0)
  • 2020-12-16 19:09

    Adding CSS3 transition/transform properties always solved any jumping issues for me with slideToggle... Example:

    -webkit-transform-origin: top;
    -moz-transform-origin: top;
    -ms-transform-origin: top;
    -o-transform-origin: top;
    transform-origin: top;
    
    -webkit-transition: transform 0.26s ease;
    -moz-transition: transform 0.26s ease;
    -ms-transition: transform 0.26s ease;
    -o-transition: transform 0.26s ease;
    transition: transform 0.26s ease;
    transition: -webkit-transform 0.26s ease;
    
    0 讨论(0)
  • 2020-12-16 19:10

    I had the same problem, but overflow:hidden and position: relative had no effect. I put margin-bottom: -10px on the element that was toggling in, and it solved the issue.

    0 讨论(0)
  • 2020-12-16 19:11

    The only thing that helped for me: give the content to scroll a width.

    0 讨论(0)
  • 2020-12-16 19:11

    I had this issue when using floated elements inside the element that is toggled. Setting a width of 100% against the toggled element fixed this for me. If you wish to use padding then you may also set the box-sizing to border-box.

    Relative positioning is not required but you may wish to use overflow: hidden to clear the floated elements.

    0 讨论(0)
  • 2020-12-16 19:15

    setting the height/width of the component you want to slide fixes a bug that causes "jumpyness" using a line like (reference):

    $('#slider').css('height', $('#slider').height() + 'px');
    
    0 讨论(0)
提交回复
热议问题