jQuery slide is jumpy

前端 未结 27 1817
悲&欢浪女
悲&欢浪女 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:42

    You just have to modify the up, down effects in effects.js to have them take into account margins or paddings that may exist and then adjust what they perceive to be the total size of the element to accommodate those values...something along these lines....

    Effect.BlindDown = function(element) {
      element = $(element);
      var elementDimensions = element.getDimensions();
    
    //below*
      var paddingtop = parseInt(element.getStyle('padding-top'));
      var paddingbottom = parseInt(element.getStyle('padding-bottom'));
      var totalPadding = paddingtop + paddingbottom;
    
      if(totalPadding > 0)
      {
       elementDimensions.height = (elementDimensions.height - totalPadding);
      }
    //above*
    
      return new Effect.Scale(element, 100, Object.extend({
        scaleContent: false,
        scaleX: false,
        scaleFrom: 0,
        scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
        restoreAfterFinish: true,
        afterSetup: function(effect) {
          effect.element.makeClipping().setStyle({height: '0px'}).show();
        },
        afterFinishInternal: function(effect) {
          effect.element.undoClipping();
        }
      }, arguments[1] || { }));
    };
    

提交回复
热议问题