jQuery方法---淡入显示与淡出隐藏

一、淡入显示

html部分

<body>
	<div class="div_top">点击显示底部盒子</div>
	<div class="div_bottom">我是底部盒子</div>
</body>

css部分

.div_top{
	width:200px;
	height:20px;
	background-color:skyblue;
}
.div_bottom{
	width:200px;
	height:70px;
	display:none;
	background-color:skyblue;
}

js部分

$(function(){
//当点击上面的盒子时,底部的盒子会显示
	$(".div_top").click(function(){
		$(".div_bottom").fadeIn();    //括号中可使用毫秒、slow、fact
	})
});

二、淡出隐藏

html部分

<body>
	<div class="div_top">点击隐藏底部盒子</div>
	<div class="div_bottom">我是底部盒子</div>
</body>

css部分

.div_top{
	width:200px;
	height:20px;
	background-color:skyblue;
}
.div_bottom{
	width:200px;
	height:70px;
	background-color:skyblue;
}

js部分

$(function(){
//当点击上面的盒子时,底部的盒子会隐藏
	$(".div_top").click(function(){
		$(".div_bottom").fadeOut();    //括号中可使用毫秒、slow、fact
	})
});

三、淡入显示与淡出隐藏切换

html部分

<body>
	<div class="div_top">点击进行底部盒子的隐藏与切换</div>
	<div class="div_bottom">我是底部盒子</div>
</body>

css部分

.div_top{
	width:200px;
	height:20px;
	background-color:skyblue;
}
.div_bottom{
	width:200px;
	height:70px;
	display:none;
	background-color:skyblue;
}

js部分

$(function(){
//当点击上面的盒子时,底部的盒子可进行显示与隐藏的切换
	$(".div_top").click(function(){
		$(".div_bottom").fadeToggle();    //括号中可使用毫秒、slow、fact
	})
});

拓展:淡出淡入设置不透明度

html部分

<body>
	<div class="div_top">点击进设置底部盒子的不透明度</div>
	<div class="div_bottom">我是底部盒子</div>
</body>

css部分

.div_top{
	width:200px;
	height:20px;
	background-color:skyblue;
}
.div_bottom{
	width:200px;
	height:70px;
	background-color:skyblue;
}

js部分

$(function(){
//当点击上面的盒子时,底部的盒子会隐藏
	$(".div_top").click(function(){
	 //括号中的两个参数分别是变换的速度与不透明度,注意两个参数必须加上
		$(".div_bottom").fadeTo("1000",0.5);   
	})
});

其中,不透明度的数值介于0~1之间,数值越小越透明。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值