<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
list-style: none;
padding:0;
margin:0;
}
.toggle-slider {
cursor: pointer;
width: 52px;
height: 31px;
background: #4BD964;
position: relative;
left: 12px;
top: 12px;
border-radius: 18px;
}
.bat {
margin: 5px;
left: 0;
position: absolute;
transition: all 600ms;
float: right;
width: 31px;
height: 30px;
background: white;
top: -5px;
border-radius: 18px;
}
.bat .face {
height: 100%;
width: 100%;
border-radius: 50%;
background: red;
position: relative;
}
.toggle-slider.morning {
transition: all 1000ms;
background: #f9ffb1;
}
.bat.awake {
left: 60%;
transform: rotate(180deg);
transition: all 600ms;
}
</style>
<script src="until/jquery/jquery-3.4.1.js"></script>
</head>
<body>
<div class="toggle-slider morning" onclick="toggle()">
<div class="bat awake">
<div class="face"></div>
</div>
</div>
<script>
function toggle() {
const bat = document.getElementsByClassName("bat")[0];
const slider = document.getElementsByClassName("toggle-slider")[0];
bat.classList.toggle("awake");
slider.classList.toggle("morning");
}
</script>
</body>
</html>
按钮点击交换事件
最新推荐文章于 2022-09-24 22:32:07 发布