源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-01-17 10:13 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:基于jquery animate操作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()取值 
});
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部