jQuery slide is jumpy

前端 未结 27 1816
悲&欢浪女
悲&欢浪女 2020-12-07 16:52

I tried to slide in and out a DIV with the toggle function of jQuery but the result is always jumpy at the start and/or end of the animation. Here\'s the js code that I use:

27条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 17:17

    I had the same problem with 'jerkyness' with divs inside my nav tag - my aim is to show an unordered list on hover of the div (if one exists). My lists are dynamically created so they do not have a fixed value.

    Heres the fix:

    $("nav div").hover(
      function() { // i.e. onmouseover function
    
        /****simple lines to fix a % based height to a px based height****/
        var h = jQuery(this).find("ul").height(); //find the height
        jQuery(this).find("ul").css("height", h); 
                             //set the css height value to this fixed value
        /*****************************************************************/
    
        jQuery(this).find("ul").slideDown("500");
      },
      function(){ // i.e. onmouseout function
        jQuery(this).find("ul").slideUp("500");
      });
    });
    

提交回复
热议问题