让zepto支持slideup(),slidedown()

zepto不支持slideup()和slidedown();使用以下方法可以支持该功能

<div class="slide">
    <p>
        zepto不支持slideup()和slidedown();使用以下方法可以支持该功能
    </p>
</div>
 
<button class="slide-trigger">点我</button>

js代码如下

(function ($) {
  $.fn.slideDown = function (duration) {    
    // get old position to restore it then
    var position = this.css('position');
    
    // show element if it is hidden (it is needed if display is none)
    this.show();
    
    // place it so it displays as usually but hidden
    this.css({
      position: 'absolute',
      visibility: 'hidden'
    });
 
    // get naturally height
    var height = this.height();
    
    // set initial css for animation
    this.css({
      position: position,
      visibility: 'visible',
      overflow: 'hidden',
      height: 0
    });
 
    // animate to gotten height
    this.animate({
      height: height
    }, duration);
  };
})(Zepto);
 
$(function () {
  $('.slide-trigger').on('click', function () {
    $('.slide').slideDown(2000);
  });
});

演示地址:http://jsfiddle.net/6zkSX/5/

原文地址:http://www.dvy.com.cn/2015/11/25/1612.html

posted @ 2017-03-02 21:13  front-gl  阅读(3259)  评论(0编辑  收藏  举报