1.思路
- ① jquery使div显示与隐藏
- ② 给点击的按钮增加css样式(包括旋转、位移等)
2.源代码
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
body {
margin: 0;
padding: 0;
}
/* 整个显示区域 */
.panelAllCss {
position: absolute;
width: 600px;
height: 600px;
outline: solid green;
}
/* 进度 标题 */
.mytitle {
position: relative;
left: 0;
top: 0;
line-height: 40px;
text-align: center;
height: 40px;
width: 100%;
background-color: darksalmon;
}
/* 旋转180度 */
.myrotate {
transition: all 1s;
transform: rotate(180deg);
left: 10px;
}
/* 箭头 */
.myarrow {
position: absolute;
width: 30px;
height: 30px;
right: 10px;
z-index: 99;
}
.myarrow:hover {
cursor: pointer;
}
</style>
</head>
<body>
<div id="panelAll" class="panelAllCss">
<!-- 箭头 -->
<img id="mybutton" src="images/left_arrow.png" class="myarrow" />
<div id="mytitle" class="mytitle">这里是标题</div>
<div id="mypanel" style="width: 300px;height:300px;position: relative;left:10px;top:10px;border: 1px solid blue;">
被隐藏的div
</div>
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script type="text/javascript">
$("#mybutton").click(function () {
$("#mytitle").toggle(200);
$("#mypanel").toggle(200);
if ($("#mybutton").hasClass('myrotate')) {
$("#mybutton").removeClass('myrotate');
} else {
$("#mybutton").addClass('myrotate');
}
})
</script>
</body>
</html>