2013-08-22 29 views
2

我想知道是否有一个jQuery函数在不使用jQuery UI的情况下执行与此代码相同的效果?没有使用jQuery UI的jQuery .show('slide')

$(selector).show('slide', { direction: 'right' }, 300); 
+0

http://jsfiddle.net/Jwkw6/1/ –

+0

@MelanciaUK,我的问题是关于如何实现上述代码的效果,而不使用jQuery UI。 –

回答

0

下面是我想出了一个快速的插件。它基本上动画的widthopacity属性:

$.fn.slideRight = function(duration, callback) { 

    duration = duration || 300; 

    return this.each(function() { 
     var $this = $(this), 
      css = getInitialStyle($this); 

     $this 
      .css({width: 0, display: 'block'}) 
      .animate(css, duration, callback); 
    }); 

    function getInitialStyle($el){ 
     var css = $el.data('initialStyle'); 

     if(!css || !css.width || !css.opacity) { 
      var isHidden = $el.is(':hidden'); 
      if(isHidden) $el.show(); 
      css = { 
       width: $el.width(), 
       opacity: $el.css('opacity') 
      } 
      if(isHidden) $el.hide(); 

      $el.data('initialStyle', css); 
     } 

     return css;    
    } 
} 

而这里的live demo

+0

我们可以从右到左做这个吗? –

+0

是的,您应该将'margin-left'属性设置为类似于'+ ='+ css.width'的属性 –