jQuery.animate() 仅带有 css 类,没有显式样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1248542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery.animate() with css class only, without explicit styles
提问by rudnev
Using JQuery animate I would like to operate with css classes, defined somewhere in .css file, not to have to give all styles params to jquery.animate() explicitly.
使用 JQuery 动画我想使用 css 类,在 .css 文件中的某处定义,不必显式地将所有样式参数提供给 jquery.animate()。
I can create a fake (e.g. invisible) element with such a class, read its css properties and give them to jquery.animate() - does anybody know a better way?
我可以用这样的类创建一个假的(例如不可见的)元素,读取它的 css 属性并将它们提供给 jquery.animate() - 有人知道更好的方法吗?
回答by Jakub Arnold
回答by Scharrels
Weston Ruther built a similar thing using the WebKit proposal for css transitions:
Weston Ruther 使用WebKit 提议为 css 转换构建了一个类似的东西:
http://weston.ruter.net/projects/jquery-css-transitions/
http://weston.ruter.net/projects/jquery-css-transitions/
This implementation might be useful for you.
此实现可能对您有用。
回答by redsquare
Check out James Padolsey's animateToSelector
查看 James Padolsey 的animateToSelector
Intro: This jQuery plugin will allow you to animate any element to styles specified in your stylesheet. All you have to do is pass a selector and the plugin will look for that selector in your StyleSheet and will then apply it as an animation.
介绍:这个 jQuery 插件将允许您将任何元素设置为样式表中指定的样式。您所要做的就是传递一个选择器,插件将在您的样式表中查找该选择器,然后将其作为动画应用。
回答by Dominic
In many cases you're better off using CSS transitions for this, and in old browsers the easing will simply be instant. Most animations (like fade in/out) are very trivial to implement and the browser does all the legwork for you. https://developer.mozilla.org/en/docs/Web/CSS/transition
在许多情况下,您最好为此使用 CSS 过渡,而在旧浏览器中,缓动将是即时的。大多数动画(如淡入/淡出)的实现非常简单,浏览器会为您完成所有的跑腿工作。https://developer.mozilla.org/en/docs/Web/CSS/transition