简体   繁体   English

jQuery使用缓动功能动画滚动到ID

[英]jQuery animate scroll to ID using easing functions

I am trying to scroll to specific ID : 我正在尝试滚动到特定ID

 $("#button1").click(function() {
        $('html, body').animate({
            scrollTop: $("#Sec1").offset().top
        }, 700);

It works fine. 工作正常。

My Question is : 我的问题是:

How do I do the same thing through easing functions ? 我如何通过缓动功能来做同样的事情?

I have tried following function but doesn't work : 我尝试了以下功能,但不起作用:

 $("#button1").click(function() {
        $('html, body').animate({
            scrollTop: $("#Sec1").offset().top
        }, 700, "easeInOutCirc");

Any suggestion would be appreciated. 任何建议,将不胜感激。

In order to use types of easing other than the default or linear , you need to include jQuery UI. 为了使用默认或linear之外的其他缓动类型,您需要包括jQuery UI。 In the animate api page for jQuery, it says "The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear." 在jQuery的动画api页面中,它说:“ jQuery库中唯一的缓动实现是默认的,称为swing,而以恒定的进度进行的线性,称为线性。”

On the jQuery UI page for easing: http://api.jqueryui.com/easings/ you can see the other types that are able to be used if you include jQuery UI. 在jQuery UI页面上进行缓动: http : //api.jqueryui.com/easings/如果包含jQuery UI,则可以看到其他可以使用的类型。

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

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