jQuery slideToggle jumps around

前端 未结 18 1337
迷失自我
迷失自我 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:03

    I had this exact same problem but only when the hidden element was a

    . I tried everything on this page but the only thing that worked was using overflow:hidden;.

    But the problem with using overflow:hidden; is that the upper & lower spacing created by the paragraph element was suddenly removed thereby making the layout ugly.

    I changed my hidden element from a

    to a

    and removed the overflow:hidden;... it worked without messing up the layout and the jumping problem did not return.

    EDIT:

    On a new site I was determined to use a hidden

    and I discovered some things about this issue...

    1) When div contains p or ul or similar the jumping occurs.

    2) When the div only contains text, a links and/or images, no jumping animation.

    3) Removing all margins & padding from the elements within the hidden div clears up the issue. Other things like line-breaks can be added to compensate for the lack of padding & margins... not ideal but the animation is smooth again.

提交回复
热议问题