开发者

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. The rule is that the effect should continue no longer than 5 minutes and at the very least be 5 seconds long.

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.

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; you should be sure to look up documentation before asking questions! http://api.jquery.com/animate/

To answer your question, jQuery's .animation() function takes in a "duration" parameter.

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/)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜