jquery如何淡出工作?对animate()做同样的事情

mat*_*att 7 jquery fade fadein zepto jquery-animate

我喜欢简单的jQuery fadeIn()函数,特别是因为它可以在不必为选择器设置任何不透明度值的情况下工作!设置它display:none并使用fadeIn()始终有效.

但是我没有在我当前的项目中使用jQuery,而是使用zepto.js.Zepto只附带animate()而不是fadeIn().

我想知道如何使用animate函数创建相同的行为!我在这里动画有什么属性?

$('#selector').animate({
    display: "block",
    opacity: 1
}, 500, 'ease-out')
Run Code Online (Sandbox Code Playgroud)

先感谢您

Sem*_*Sem 8

(function($){
      $.extend($.fn, {
        fadeIn: function(ms){
          if(typeof(ms) === 'undefined'){
            ms = 250;
          }
          $(this).css({
            display: 'block',
            opacity:0
          }).animate({
            opacity: 1
          }, ms);
          return this;
        }
      })
    })(Zepto)
Run Code Online (Sandbox Code Playgroud)

如果Zepto像jQuery一样工作$('.example').fadeIn();应该做的伎俩.

编辑:Trejder是对的,调整了部分.