首頁  >  文章  >  web前端  >  基於jquery animate操作css樣式屬性小結_jquery

基於jquery animate操作css樣式屬性小結_jquery

PHP中文网
PHP中文网原創
2016-05-16 15:29:231141瀏覽

昨天突然有網友問我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 屬性小結jquery的內容,更多相關內容請關注PHP中文網(www.php.cn)!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn