177 lines
4.3 KiB
HTML
177 lines
4.3 KiB
HTML
<!DOCTYPE html>
|
|
<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>下拉滑动</title>
|
|
<style>
|
|
body,
|
|
ul,
|
|
li {
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
.main {
|
|
position: relative;
|
|
}
|
|
|
|
.main ul {
|
|
overflow: hidden;
|
|
margin-top: 45px;
|
|
}
|
|
|
|
.main ul li {
|
|
display: flex;
|
|
height: 45px;
|
|
align-items: center;
|
|
position: relative;
|
|
padding: 0 15px;
|
|
border-bottom: 1px solid #f4f0f0;
|
|
transition-duration: 0.3s;
|
|
}
|
|
|
|
.main .item {
|
|
width: 100%;
|
|
}
|
|
|
|
.main .action {
|
|
display: flex;
|
|
align-items: center;
|
|
height: 100%;
|
|
position: absolute;
|
|
right: -180px;
|
|
}
|
|
|
|
.main .action .item {
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 0 14px;
|
|
color: #fff;
|
|
}
|
|
|
|
.head {
|
|
z-index: 999;
|
|
}
|
|
|
|
.head ul {
|
|
height: 45px;
|
|
line-height: 45px;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
}
|
|
|
|
.head ul li {
|
|
display: inline-block !important;
|
|
float: left;
|
|
margin-left: 20px;
|
|
}
|
|
|
|
.shuaxin {
|
|
width: 30px;
|
|
height: 30px;
|
|
position: absolute;
|
|
top: -30px;
|
|
right: 50%;
|
|
z-index: 2;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="head">
|
|
<ul>
|
|
<li>
|
|
推荐
|
|
</li>
|
|
<li>
|
|
热门
|
|
</li>
|
|
<li>
|
|
动画
|
|
</li>
|
|
<li>
|
|
影视
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="main">
|
|
<img src="./img/shuaxin.png" alt="" height="30px" width="30px" class="shuaxin">
|
|
<ul>
|
|
<li>
|
|
<div class="item">内容1</div>
|
|
</li>
|
|
<li>
|
|
<div class="item">内容2</div>
|
|
</li>
|
|
<li>
|
|
<div class="item">内容3</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
<script>
|
|
var startY = 0;
|
|
_(".shuaxin").forEach((v, i) => {
|
|
|
|
_(".shuaxin").forEach((v, i) => {
|
|
v.open = false
|
|
v.addEventListener('touchstart', (e) => {
|
|
startY = e.targetTouches[0].screenY;
|
|
|
|
_(".shuaxin").forEach((j, index) => {
|
|
if (index != i) {
|
|
j.style.transform = `translateY(-30px)`;
|
|
}
|
|
})
|
|
console.log("startY: ", startY);
|
|
})
|
|
|
|
v.addEventListener('touchmove', (e) => {
|
|
var moveY = e.targetTouches[0].screenY
|
|
if (!v.open) {
|
|
var y = moveY - startY
|
|
console.log("下滑:",);
|
|
v.style.transform = `translateY(${
|
|
y < 50 ? y : 50}px)`
|
|
v.open=true
|
|
}
|
|
else {
|
|
if (v.open) {
|
|
var newY = -50 + (moveY - startY)
|
|
v.style.transform = `translateY(${newY <= 0 ? 0 : newY}px)`;
|
|
}
|
|
}
|
|
})
|
|
})
|
|
v.addEventListener('touchend', (e) => {
|
|
var endY = e.changedTouches[0].screenY;
|
|
var ox = endY -startY
|
|
|
|
if (startY < endY) {
|
|
if (ox < 250) {
|
|
v.style.transform = `translateY(0px)`
|
|
v.open = false
|
|
}
|
|
else {
|
|
v.style.transform = `translateY(250px)`
|
|
setTimeout(function(){
|
|
v.style.transform = `translateY(0px)`},3000);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
function $(className) {
|
|
return document.querySelector(className)
|
|
}
|
|
function _(className) {
|
|
return document.querySelectorAll(className)
|
|
}
|
|
</script>
|
|
|
|
</html> |