设置块级元素的隐藏和显示

设置块级元素的隐藏和显示

Html

<div id="sel_1" class="col-xs-12 col-sm-12" style="visibility: hidden;height: 0px;">				
	<label class="form-label col-xs-8 col-sm-6">id</label>						
	<input id="type"  type="password" class="input-text" autocomplete="off"						
</div>
<a href="javascript:void(0);" οnclick="hiden()" class="btn btn-primary radius">点击隐藏/显示</a>


JavaScript

<script>
			function hiden() {
				if(document.getElementById('sel_1').style.visibility == "hidden") {
					document.getElementById('sel_1').style.visibility = 'visible';
					document.getElementById('sel_1').style.height = '20%';
				} else {
					document.getElementById('sel_1').style.visibility = 'hidden';
					setTimeout(hiden_2, 1000);//设置延时

				}

			}

			function hiden_2() {
				document.getElementById('sel_1').style.height = '0';
			}
		</script>


以下是使用jQuery完成按键点击实现图片或者块级元素显示隐藏、淡入、淡出以及半透明动画效果的例子: 1. 显示隐藏图片 ```html <!DOCTYPE html> <html> <head> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#hide").click(function(){ $("img").hide(); }); $("#show").click(function(){ $("img").show(); }); }); </script> </head> <body> <button id="hide">隐藏图片</button> <button id="show">显示图片</button> <br><br> <img src="https://www.w3school.com.cn/i/eg_tulip.jpg" alt="鲜花" width="100" height="100"> </body> </html> ``` 2. 淡入和淡出图片 ```html <!DOCTYPE html> <html> <head> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#fadeOut").click(function(){ $("img").fadeOut(); }); $("#fadeIn").click(function(){ $("img").fadeIn(); }); }); </script> </head> <body> <button id="fadeOut">淡出图片</button> <button id="fadeIn">淡入图片</button> <br><br> <img src="https://www.w3school.com.cn/i/eg_tulip.jpg" alt="鲜花" width="100" height="100"> </body> </html> ``` 3. 半透明图片 ```html <!DOCTYPE html> <html> <head> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#opacity").click(function(){ $("img").css("opacity", "0.5"); }); }); </script> </head> <body> <button id="opacity">半透明图片</button> <br><br> <img src="https://www.w3school.com.cn/i/eg_tulip.jpg" alt="鲜花" width="100" height="100"> </body> </html> ``` 4. 显示隐藏块级元素 ```html <!DOCTYPE html> <html> <head> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); }); }); </script> </head> <body> <button id="hide">隐藏段落</button> <button id="show">显示段落</button> <br><br> <p>这是一个段落。</p> <p>这是另一个段落。</p> </body> </html> ``` 5. 淡入和淡出块级元素 ```html <!DOCTYPE html> <html> <head> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#fadeOut").click(function(){ $("p").fadeOut(); }); $("#fadeIn").click(function(){ $("p").fadeIn(); }); }); </script> </head> <body> <button id="fadeOut">淡出段落</button> <button id="fadeIn">淡入段落</button> <br><br> <p>这是一个段落。</p> <p>这是另一个段落。</p> </body> </html> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值