<!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>
<style>@charset "utf-8";
/*==================================================
2本線が「×」に
===================================*/
/*ボタン外側※レイアウトによってpositionや形状は適宜変更してください*/
.openbtn {
position: relative; /*ボタン内側の基点となるためrelativeを指定*/
width: 50px;
height: 50px;
cursor: pointer;
background: #fff;
}
/*ボタン内側*/
.openbtn span {
display: inline-block;
transition: all 0.4s; /*アニメーションの設定*/
position: absolute;
left: 13px;
height: 2px;
background-color: #666;
}
.openbtn span:nth-of-type(1) {
top: 22px;
width: 50%;
}
.openbtn span:nth-of-type(2) {
top: 29px;
width: 30%;
}
/*activeクラスが付与されると線が回転して×に*/
.openbtn.active span:nth-of-type(1) {
top: 20px;
left: 16px;
transform: translateY(6px) rotate(-45deg);
width: 35%;
}
.openbtn.active span:nth-of-type(2) {
top: 32px;
left: 16px;
transform: translateY(-6px) rotate(45deg);
width: 35%;
}
/*========= レイアウトのためのCSS ===============*/
body {
background: #aaa;
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>
</div>
<p class="lead">クリックしてね</p>
<script>$(".openbtn").click(function () {
$(this).toggleClass("active");
});
//# sourceURL=pen.js</script>
</body>
</html>