AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

基于jquery animate操作css样式属性小结

51自学网 http://www.wanshiok.com
jquery_animate_css, jquery_css样式

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

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

 * 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属性

如题,举例:

$('body').animate({scrollTop:0}, 1500);$("body").animate({scrollTop:"-="+50},350);

还有其他的几个小例子:

禁用元素:

$('button').attr('disabled', 'disabled'); $('button').removeAttr('disabled');

遍历元素集合:

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

jquery_animate_css, jquery_css样式  
上一篇:JS实现的表格行鼠标点击高亮效果代码  下一篇:Javascript简单实现面向对象编程继承实例代码