Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement jquery like slideDown() in zepto

I am using zepto library for my mobile web site. I have recently learnt that zepto does not have slideDown() plugin like jquery. I would like to implement the same for zepto.

I have tried one on jsfiddle (http://jsfiddle.net/goje87/keHMp/1/). Here it does not animate while showing the element. It just flashes down. How do I bring in the animation?

PS: I cannot provide a fixed height because I would be applying this plugin to the elements whose height property would not be known.

Thanks in advace!!

like image 955
Goje87 Avatar asked Sep 05 '12 05:09

Goje87


4 Answers

This would work for what you need: https://github.com/NinjaBCN/zepto-slide-transition

like image 186
kennersky Avatar answered Nov 09 '22 05:11

kennersky


Demo: http://jsfiddle.net/6zkSX/5

JavaScript:

(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);
  });
});​
​
like image 35
Danil Speransky Avatar answered Nov 19 '22 06:11

Danil Speransky


This worked for me:

https://github.com/Ilycite/zepto-slide-transition

The Zepto Slide Transition plugin add to Zepto.js the functions bellow :

slideDown();

slideUp();

slideToggle();

like image 5
rauff Avatar answered Nov 19 '22 05:11

rauff


Speransky's answer was helpful, and I'm offering a simplified alternative for a common drop-down navigation list, and separated into slideUp and slideDown on jsfiddle: http://jsfiddle.net/kUG3U/1/

$.fn.slideDown = function (duration) {
    // show element if it is hidden (it is needed if display is none)
    this.show();

    // get naturally height
    var height = this.height();

    // set initial css for animation
    this.css({
        height: 0
    });

    // animate to gotten height
    this.animate({
        height: height
    }, duration);
};
like image 1
Frank Yin Avatar answered Nov 19 '22 06:11

Frank Yin