我是靠谱客的博主 苹果马里奥,这篇文章主要介绍基于jquery animate操作css样式属性小结,现在分享给大家,希望可以做个参考。

昨天突然有网友问我animate()方法可以来操作所有css属性吗?是的,我告诉他可以的。不过,在此有需要注意点需要大家搞清楚:当使用 animate()时,必须使用 Camel 标记法书写所有的属性名,比如,必须使用 paddingLeft 而不是 padding-left,使用 marginRight而不是 margin-right,等等。

css中的不是所有属性都可以用Jquery动画(animate函数)来动态改变,下面总结了JQ可以操作元素的一些属性:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
* backgroundPosition * borderWidth * borderBottomWidth * borderLeftWidth * borderRightWidth * borderTopWidth * borderSpacing * margin * marginBottom * marginLeft * marginRight * marginTop * outlineWidth * padding * paddingBottom * paddingLeft * paddingRight * paddingTop * height * width * maxHeight * maxWidth * minHeight * maxWidth * font * fontSize(在animate函数的css参数指定并不同于标准css属性,例如这个css标准是:font-size。同理上面很多也是这样的情况) * bottom * left * right * top * letterSpacing * wordSpacing * lineHeight * textIndent * opacity

记住这些可以玩动画的哦~~

jquery的animate()方法也可设置非css属性

如题,举例:

复制代码
1
2
$('body').animate({scrollTop:0}, 1500); $("body").animate({scrollTop:"-="+50},350);

还有其他的几个小例子:

禁用元素:

复制代码
1
2
$('button').attr('disabled', 'disabled'); $('button').removeAttr('disabled');

遍历元素集合:

复制代码
1
2
3
4
5
$("input:text").each(function(index){ alert(index);//循环的下标值,从0开始 alert(this.value);//自带属性可以用this(Dom)直接取值 alert($(this).attr("type"));//自定义属性需要用attr()取值 });

最后

以上就是苹果马里奥最近收集整理的关于基于jquery animate操作css样式属性小结的全部内容,更多相关基于jquery内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(143)

评论列表共有 0 条评论

立即
投稿
返回
顶部