jQuery slideToggle jumps around

前端 未结 18 1305
迷失自我
迷失自我 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条回答
  •  萌比男神i
    2020-12-16 19:00

    Accidentally I think that the easiest to use solution is to add custom function to jQuery with animate padding/margin-top/bottom too.

    //this function is to avoid slideToggle jQuery jump bug.
    $.fn.slideShow = function(time,easing) { return $(this).animate({height:'show','margin-top':'show','margin-bottom':'show','padding-top':'show','padding-bottom':'show',opacity:1},time,easing); }
    $.fn.slideHide = function(time,easing) {return $(this).animate({height:'hide','margin-top':'hide','margin-bottom':'hide','padding-top':'hide','padding-bottom':'hide',opacity:0},time,easing);  }
    

    And useage example:

    $(this).slideShow(320,'easeOutQuart');
    $(this).slideHide(320,'easeOutQuart');
    

    My example animated opacity toggle tu, you can modify it as you need.

提交回复
热议问题