简体   繁体   English

如何更改jQuery动画的持续时间?

[英]How do I change the duration of a jQuery animation?

I want to show some effect (animate) with the help of jQuery during the time that should be calculated based on how many results are found for a particular needle. 我想在jQuery的帮助下显示一些效果(动画),该效果应根据针对特定针头找到的结果数来计算。 The rule is that the effect should continue no longer than 5 minutes and at the very least be 5 seconds long. 规则是效果应持续不超过5分钟,并且至少应持续5秒。

So, here's what I do in particular. 所以,这就是我特别要做的。 I search a database for a particular word the user inputs and count the results. 我在数据库中搜索用户输入的特定单词并计算结果。 Then I search a myself defined word in the same database and count the results. 然后,我在同一数据库中搜索自己定义的单词并计算结果。 If there are more the latter results than the former results, I need to calculate how long to show the effect. 如果后一个结果比前一个结果多,我需要计算显示效果的时间。 The more the latter results found, the shorter the time the effect should continue. 发现的结果越多,效果持续的时间越短 Plus, I need to obey the rule: no longer than 5 minutes, no less than 5 seconds. 另外,我需要遵守规则:不超过5分钟,不少于5秒。

I need that to be accurate at best. 我最好做到这一点。

That may be a stupid question but I cannot figure out on my own how to calculate the time! 这可能是一个愚蠢的问题,但我无法自己弄清楚如何计算时间! :) :)

jQuery is really well documented; jQuery的文档非常丰富; you should be sure to look up documentation before asking questions! 您应该确保在问问题之前先查阅文档! http://api.jquery.com/animate/ http://api.jquery.com/animate/

To answer your question, jQuery's .animation() function takes in a "duration" parameter. 为了回答您的问题,jQuery的.animation()函数采用“ duration”参数。

For instance: 例如:

$myElement = $("#animatedObject");
$myElement.animate({"width": 500}, 6000); // would animate the width of the object to be 500 pixels over 6000 milliseconds (i.e. 6 seconds).

Just pass in the duration as the second parameter. 只需将持续时间作为第二个参数。

If you are asking how to actually calculating that duration, you really need to figure that out yourself or be more clear about where you are facing problems. 如果您要问如何实际计算持续时间,您确实需要弄清楚自己的身分,或者更清楚地了解您面临的问题。 As it stands it sounds like you haven't attempted to solve this one on your own. 就目前而言,这听起来好像您还没有尝试自己解决这个问题。 As a good starting point, though you will probably want to communicate with some server side scripts using AJAX (http://api.jquery.com/category/ajax/) 作为一个好的起点,尽管您可能希望使用AJAX与某些服务器端脚本进行通信(http://api.jquery.com/category/ajax/)

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

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