简体   繁体   English

轻松使用jQuery动画

[英]ease-in with jQuery animation

Simple question, but I can't find a way to do it. 这个问题很简单,但是我找不到解决方法。 I have a jQuery animation that scrolls the page to an element: 我有一个jQuery动画,可将页面滚动到一个元素:

$('html, body').animate({scrollTop: $("#element").offset().top},1000);

I want the animation to have a slow start and a fast end (ease-in in css). 我希望动画具有慢速开始和快速结束的效果(在CSS中简化)。 It should work like this: 它应该像这样工作:

$('html, body').animate({scrollTop: $("#maine").offset().top},1000, "ease-in");

Is there any way to do this? 有什么办法吗?

There are only two easing functions available in plain jQuery: linear and swing . 普通jQuery中只有两个缓动函数可用: linearswing

Click the black box to see how it works with swing: https://jsfiddle.net/o95dq69m/ 单击黑框以查看它如何与swing配合使用: https : //jsfiddle.net/o95dq69m/

$(this).animate({'top': topVal}, 500, 'swing', function(){});

If you are not afraid of using extra libraries, go ahead and try jQuery-UI , there is a ton of easing functions available there, like easeInExp : https://jsfiddle.net/o95dq69m/1/ 如果您不担心使用额外的库,请继续尝试jQuery-UI ,那里提供了大量的缓动函数,例如easyInExphttps : //jsfiddle.net/o95dq69m/1/

$(this).animate({'top': topVal}, 500, 'easeInExpo', function(){});

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

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