更改隐藏/显示链接的背景图像并切换ul

时间:2018-06-23 11:57:41

标签: jquery image background toggle

当我单击作为背景图像的“ +”符号时,我正在尝试扩展“ ul”。同时,我希望该“ +”号的背景图像更改为https://image.ibb.co/d7gQUo/genmoo_Hide.jpg

我希望你们能帮助我。我是Jquery的新手,解决这个问题对我有很多帮助。我从来没有尝试过单击2个命令来切换单击链接的背景图像,并隐藏/显示其下的列表。

@charset "utf-8";
* {
	padding:0;
	margin:0;
	}
body {
	font-family:Arial, Helvetica, sans-serif;
	}
.panel {
	width:200px;
	padding:20px;
	border:1px solid #ccc;
	position:relative;
	}
h3 {
	font-size:1em;
	line-height:20px;
	}
span.hideshow {
	position:absolute;
	top:20px;
	right:20px;
	}
	span.hideshow a {
		display:block;
		height:20px;
		width:20px;
		text-indent:-9999px;
		background-image:url("https://image.ibb.co/bvkkUo/genmoo_Show.jpg");
    /* URL for show image = https://image.ibb.co/bvkkUo/genmoo_Hide.jpg */
		}

ul {
  display:none;
	margin-top:15px;
	list-style-type:none;
	}
li {
	line-height:24px;
	border-bottom:1px solid #eee;
	}
	li:last-child {
		border-bottom:none;
		}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hide Show Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>

<div class="panel">
	<h3>Teams</h3>
    <span class="hideshow"><a href="#">.</a></span>
    <ul>
    	<li>Arsenal</li>
        <li>Chelsea</li>
        <li>Liverpool</li>
        <li>Man United</li>
    </ul>
</div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我认为您应该使用切换按钮, 请检查此示例

input[type="checkbox"] {
    display:none;
}

input[type="checkbox"] + span {
    display:inline-block;
    width:19px;
    height:19px;
    padding-top: 5px; /* align the label with the image*/
    vertical-align:middle;
    background:url(http://icons.iconseeker.com/png/fullsize/mazes-mini/02-laugh.png) left top no-repeat;
    cursor:pointer;
}

input[type="checkbox"]:checked +  span {
    background:url(http://icons.iconseeker.com/png/fullsize/mazes-mini/01-smile.png) left top no-repeat;
}
<label>Expand 
    <input type="checkbox" id="c1" name="cc" class="mycheckbox" />
    <span></span>
</label>