jquery特别注意:animate 不支持 display:none;block

不是所有样式属性都 会被动画 animate 所支持的。比如我今天做的一个小demo,js代码如下:

【解决方案】如果实在要显示隐藏对象,可以操作它的opacity属性来控制;

特别注意: 当与 animate() 方法一起使用时,该属性名称必须是驼峰写法: 您必须使用 paddingLeft 代替 padding-left,marginRight 代替 margin-right,依此类推。

$(function(){
				$("#btn-menu").click(function(){
				var current_opacity = $(".slidebar").css("opacity")
					if( current_opacity==1)
				
					{
						//特别注意:animate 不支持 display:none;block
						
						$(".right").animate({ 
	                    	marginLeft:0,
						}, 700, 'easeOutCubic');  
						
						$(".slidebar").animate({ 
                  		 	width:0,
	                    	opacity:0
						    //display: "none"  
						}, 50, 'easeOutCubic');		                 			 
					}
					else
					{ 
						$(".right").animate({ 
	                    	marginLeft:200,
						}, 700, 'easeOutCubic');  
						
						$(".slidebar").animate({ 
	                    	width:200,
	                    	opacity:1
						    //display: "block" 
						},  700, 'easeOutCubic');	
					}
					
				})
			})

以下样式可以用作动画: 

* 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

 

转载于:https://my.oschina.net/u/583531/blog/915709

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值