1 回答
TA贡献1835条经验 获得超7个赞
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
html{
height : 200%;
}
#position{
width : 100px;
height : 100px;
position: absolute;
top : 100%;
left: 80%;
background: red;
}
</style>
<body >
<div id="position"></div>
</body>
<script>
(()=>{
let pos = document.getElementById('position');
pos.onclick = ()=>{
let curr_top = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
let time_id = setInterval(()=>{
curr_top -= 10;
document.body.scollTop = curr_top;
document.documentElement.scrollTop = curr_top;
if(curr_top <= 0){
clearInterval(time_id);
}
} , 100);
}
})()
</script>
</html>
添加回答
举报