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

來源:互聯網
上載者:User

昨天突然有網友問我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()取值 });

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.