<!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";
/*==================================================
MENUがCLOSEに
===================================*/
/*ボタン外側※レイアウトによってpositionや形状は適宜変更してください*/
.openbtn {
position: relative; /*ボタン内側の基点となるためrelativeを指定*/
background: #d54884;
cursor: pointer;
width: 50px;
height: 50px;
border-radius: 5px;
}
/*ボタン内側*/
.openbtn span {
display: inline-block;
transition: all 0.4s; /*アニメーションの設定*/
position: absolute;
left: 14px;
height: 2px;
border-radius: 5px;
background: #fff;
width: 45%;
}
.openbtn span:nth-of-type(1) {
top: 13px;
}
.openbtn span:nth-of-type(2) {
top: 19px;
}
.openbtn span:nth-of-type(3) {
top: 25px;
}
.openbtn span:nth-of-type(3)::after {
content: "Menu"; /*3つ目の要素のafterにMenu表示を指定*/
position: absolute;
top: 5px;
left: -2px;
color: #fff;
font-size: 0.6rem;
text-transform: uppercase;
}
/*activeクラスが付与されると線が回転して×になり、Menu⇒Closeに変更*/
.openbtn.active span:nth-of-type(1) {
top: 14px;
left: 18px;
transform: translateY(6px) rotate(-45deg);
width: 30%;
}
.openbtn.active span:nth-of-type(2) {
opacity: 0;
}
.openbtn.active span:nth-of-type(3) {
top: 26px;
left: 18px;
transform: translateY(-6px) rotate(45deg);
width: 30%;
}
.openbtn.active span:nth-of-type(3)::after {
content: "Close"; /*3つ目の要素のafterにClose表示を指定*/
transform: translateY(0) rotate(-45deg);
top: 5px;
left: 4px;
}
/*========= レイアウトのための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>