简体   繁体   English

使用jQuery简化Animate Scroll

[英]Easing on Animate Scroll with jQuery

I'm trying to create an ease effect on my animate function in jQuery, but I'm having some trouble. 我试图在jQuery的动画函数上创建轻松效果,但是遇到了一些麻烦。 Here's what I have so far: 这是我到目前为止的内容:

function myCustomFunction(id){
    var divTag = $("div[name='"+ id +"']");
    $('html,body').animate({scrollTop: divTag.offset().top}, 800);
}

The ease I want to use is called "easeOutQuint". 我想使用的简便性称为“ easeOutQuint”。 I tried to follow the example here ( http://easings.net/#easeOutQuint ) but wasn't able to apply the example to my function. 我尝试按照此处的示例( http://easings.net/#easeOutQuint )进行操作,但无法将该示例应用于我的函数。

Firstly, include first script from section download on this page:( http://gsgd.co.uk/sandbox/jquery/easing/ ). 首先,在此页面的下载部分中包含第一个脚本:( http://gsgd.co.uk/sandbox/jquery/easing/ )。

Then type jQuery animate line like this below: 然后像下面这样输入jQuery动画行:

function myCustomFunction(id){
var divTag = $("div[name='"+ id +"']");
$('html,body').animate({scrollTop: divTag.offset().top}, 800, 'easeOutQuint');
}

Here you can see example... http://jsfiddle.net/Gq367/ 在这里您可以看到示例... http://jsfiddle.net/Gq367/

As you can see, you missed the easing parameter in jquery animate function. 如您所见,您错过了jQuery animate函数中的easing参数。 Quick reminder: .animate( properties [, duration ] [, easing ] [, complete ] ) 快速提醒:.animate(属性[,持续时间] [,缓动] [,完整])

I'm interested why you select div by name attribute? 我对您为什么选择div by name属性感兴趣?

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

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