简体   繁体   English

jQuery 淡入淡出

[英]jQuery fadeIn ease

I use below jQuery script to fade in my dropdown-menu.我使用下面的 jQuery 脚本淡入我的下拉菜单。 How do I use easing in this example?在这个例子中我如何使用easing

  $('ul.navbar-nav li.dropdown').hover(function() {
    $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(50);
  }, 
  function() {
    $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(50);
  });

As mentioned in jQuery fadeIn documentation ,正如jQuery 淡入文档中提到的,

As of jQuery 1.4.3, an optional string naming an easing function may be used.从 jQuery 1.4.3 开始,可以使用命名缓动函数的可选字符串。 Easing functions specify the speed at which the animation progresses at different points within the animation.缓动函数指定动画在动画中不同点的速度。 The only easing implementations in the jQuery library are the default, called swing , and one that progresses at a constant pace, called linear . jQuery 库中唯一的缓动实现是默认的,称为swing ,和一个以恒定速度进行的,称为linear More easing functions are available with the use of plug-ins, most notably the jQuery UI suite .通过使用插件,可以使用更多缓动功能,最显着的是jQuery UI 套件

Here is the syntax这是语法

$(selector).fadeIn(speed,easing,callback)

Here is an example这是一个例子

$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500,"linear");

fadeIn() method has 3 parameters. fakeIn() 方法有 3 个参数。 You can pass easing parameter to fadeIn() function.您可以将缓动参数传递给fadeIn() 函数。

fadeIn() syntax:淡入淡出()语法:

$(selector).fadeIn(speed,easing,callback)

Change your code from:更改您的代码:

$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(50);

To:到:

$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(50,"Easing Type");

For more details check fadeIn() method:有关更多详细信息,请查看fadeIn() 方法:

https://www.w3schools.com/jquery/eff_fadein.asp https://www.w3schools.com/jquery/eff_fadein.asp

$(selector).fadeIn(speed,easing,callback) $(selector).fadeIn(speed,easing,callback)

$(selector).fadeOut(speed,easing,callback) $(selector).fadeOut(speed,easing,callback)

To use different easing options in jQuery fadeIn/fadeOut, you need to fill in the second parameter要在jQuery的fadeIn/fadeOut中使用不同的缓动选项,需要填写第二个参数

Example:例子:

$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(50,'linear',function(){});

The existing ease option for jQuery will be swing and linear .现有的 jQuery 简易选项将是swinglinear If you need more options you will need to use jQuery UI suite如果您需要更多选项,则需要使用jQuery UI 套件

From jQuery fadeIn documentation来自 jQuery淡入淡出文档

Easing宽松

As of jQuery 1.4.3, an optional string naming an easing function may be used.从 jQuery 1.4.3 开始,可以使用命名缓动函数的可选字符串。 Easing functions specify the speed at which the animation progresses at different points within the animation.缓动函数指定动画在动画中不同点的速度。 The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. jQuery 库中唯一的缓动实现是默认的,称为swing,和一个以恒定速度进行的,称为linear。 More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.使用插件可以使用更多缓动功能,尤其是 jQuery UI 套件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM