<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
}
.app {
width: 1200px;
height: 50px;
background-color: lawngreen;
margin: 25% auto;
display: flex;
align-items: center;
position: relative;
}
.precess {
width: 100%;
height: 30px;
border-radius: 15px;
background-color: #ebeef5 ;
}
.left {
height: 30px;
width: 0;
border-radius: 15px;
background-color: #f56c6c;
}
.bar {
width: 50px;
height: 50px;
border-radius: 50%;
background-color: #f56c6c;
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
justify-content: center;
transform: translateX(-50%);
}
.bar-cli {
width: 30px;
height: 30px;
border-radius: 50%;
background-color: white;
}
</style>
</head>
<body>
<div class="app">
<div class="precess">
<div class="left"></div>
</div>
<div class="bar">
<div class="bar-cli"></div>
</div>
</div>
<script>
let oPrecess = document.getElementsByClassName('precess')[0]
let oBar = document.getElementsByClassName('bar')[0]
let oLeft = document.getElementsByClassName('left')[0]
let precessWidth = oPrecess.offsetWidth
let setp = precessWidth / 100
let i = 0
let startX = 0
let moveX = 0
let timer = setInterval(() => {
mMoveBarX()
}, 1000);
oBar.onmousedown = function (e) {
clearInterval(timer)
startX = e.clientX - oBar.offsetLeft
document.onmousemove = function(e) {
moveX = e.clientX - startX
if(moveX >= precessWidth) {
moveX = precessWidth
} else if(moveX <= 0){
moveX = 0
}
moveBarX (moveX)
}
document.onmouseup = function () {
document.onmousemove = null
startMMove()
}
}
oPrecess.onmousedown = function(e) {
clearInterval(timer)
moveX = e.offsetX
moveBarX(moveX)
}
oPrecess.onmouseup = function() {
startMMove()
}
function startMMove() {
timer = setInterval(() => {
mMoveBarX()
}, 1000);
}
function mMoveBarX() {
if(moveX < precessWidth) {
moveX = (precessWidth / 100) + moveX
if(moveX > precessWidth) {
moveX = precessWidth
}
moveBarX(moveX)
} else {
clearInterval(timer)
}
}
function moveBarX (moveX) {
oBar.style.left = moveX + 'px'
oLeft.style.width = oBar.style.left
}
</script>
</body>
</html>```
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通