jQuery学习:显示隐藏 --点击图片显示隐藏

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery-3.6.1.js"></script>
		<style>
			a {
				text-decoration: none;
				background: #bfa;
				padding: 2px;
				width: 10px;
				height: 10px;
			}

			#sharemore b {
				padding: 2px;
				width: 10px;
				height: 10px;
			}


			.lf {
				background: deeppink;
				width: 185px;
				padding: 5px;
				text-align: center;
			}

		
		</style>
	</head>
	<body>
		<div class="lf" id="dd">
			<!-- 需要改变宽度 -->
			<span>分享到:</span>
			<a href="#" class="share_sina">&#x1F600;</a>
			<a href="#" class="share_qq">&#x1F608;</a>
			<a href="#" class="share_renren">&#x1F60E;</a>

			<a href="#" class="share_kaixin" style="display: none;">&#x1F92A;</a><!-- 需要改变显示 -->
			<a href="#" class="share_douban" style="display: none;">&#x1F630;</a><!-- 需要改变宽度 -->
			<!-- &#x25B6;
			&#x25C0;</a> -->
			<!-- 触发事件 -->
			<a href="#" class="sharemore" id="sharemore">
				<b class="">&#x25B6;</b>
			</a>
		</div>
		<script>
			share();

			function share() {
				var isClose = true; //标识当前状态是关闭
				var $sharemore = $('#sharemore');
				var $parent = $sharemore.parent();
				//查找前面所有的兄弟---只需要钱敏的两个 发现是逆序的用 html eq等测试
				var $hida = $sharemore.prevAll('a:lt(2)');
				var $b = $sharemore.children()
				//触发事件的元素
				$sharemore.click(function() {
					if (isClose) { //关闭状态
						$parent.css('width', '250');
						$b.html('&#x25C0;');
						console.log($b.val())
						$hida.show();

					} else { //去打开
						
						$parent.css('width', '185');
							$b.html('&#x25B6;');
						$hida.hide();
					}
						isClose = !isClose;
				})
			}
		</script>
	</body>
</html>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值