<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous">
</script>
<script src="js/5-2-3.js">
</script>
<style>@charset "utf-8";
/*==================================================
3本線が1本線に
===================================*/
/*ボタン外側※レイアウトによってpositionや形状は適宜変更してください*/
.openbtn {
position: relative; /*ボタン内側の基点となるためrelativeを指定*/
background: #4c9f1e;
cursor: pointer;
width: 50px;
height: 50px;
border-radius: 5px;
}
/*ボタン内側*/
.openbtn span {
display: inline-block;
transition: all 0.4s; /*アニメーションの設定*/
position: absolute;
left: 14px;
height: 3px;
border-radius: 2px;
background: #fff;
width: 45%;
}
.openbtn span:nth-of-type(1) {
top: 15px;
}
.openbtn span:nth-of-type(2) {
top: 23px;
}
.openbtn span:nth-of-type(3) {
top: 31px;
}
/*activeクラスが付与されると1・3番目の要素が2番目の要素と同じ位置になり一本線に*/
.openbtn.active span:nth-of-type(1),
.openbtn.active span:nth-of-type(3) {
top: 23px;
}
/*========= レイアウトのためのCSS ===============*/
body {
background: #f3f3f3;
padding: 20px;
}
a {
color: #333;
text-decoration: none;
}
.lead {
margin: 20px 0 0 0;
}</style>
</head>
<body>
<body>
<div class="openbtn">
<span>
</span>
<span>
</span>
<span>
</span>
</div>
<p class="lead">クリックしてね</p>
<script>$(".openbtn").click(function () {
$(this).toggleClass("active");
});
//# sourceURL=pen.js</script>
</body>
</html>