移动端左滑出现标记成未读及删除按钮

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

<title>Document</title>

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Document</title>

<!-- <style>.contents {position: relative;height: 4rem;border-bottom: .01rem solid #ccc;margin-bottom: .2rem;overflow: hidden;}.w115 {width: 130%;}.package {height: 4rem;-webkit-transition: all 0.3s linear;transition: all 0.3s linear;}.lefti {width: 15%;height:4rem;position: absolute;top: 0;left: 0;}.leftimg {display: block;font-style: normal;margin: 1.3rem auto;height: 1.7rem;width: 1.7rem;border: .01rem solid #435057;background: #99beee;border-radius: 50%;line-height: 1.7rem;font-size: .13rem;color: #7a95a3;text-align: center;}.text {position: absolute;top: 0;left: 15%;width: 74%;height: 4rem;color: #7a95a3;font-family: "幼圆";font-size: .22rem;line-height: 4rem;}.delete {position: absolute;top: 0;right: -45%;width: 45%;-webkit-transition: all 0.5s linear;transition: all 0.5s linear;}.biao1{float:left;font-size: .22rem;text-align: center;line-height: 4rem;color: #fff;width:48%;height: 4rem;background: #ccc; -webkit-transition: all 0.5s linear;transition: all 0.5s linear;}.del1{float:left;font-size: .22rem;text-align: center;line-height: 4rem;color: #fff;width:30%;height: 4rem;background: red;-webkit-transition: all 0.5s linear;transition: all 0.5s linear;}.delete1 {position: absolute!important;top: 0!important;right: -35%!important;width:15%!important;font-size: .22rem!important;text-align: center!important;line-height: 4rem!important;color: #fff!important;height: 4rem!important;background: red!important;-webkit-transition: all 0.5s linear!important;transition: all 0.5s linear!important;}.swipeleft {-webkit-transition: all 0.5s linear;transition: all 0.5s linear;transform: translateX(-35%);-webkit-transform: translateX(-35%);}.pan{position:absolute;right:10px;line-height:4rem;color:rgb(138, 145, 145);}.swiperight {-webkit-transition: all 0.5s linear;transition: all 0.5s linear;transform: translateX(0%);-webkit-transform: translateX(0%);}</style> -->

<style>

.contents {

position: relative;

height: 4rem;

border-bottom: .01rem solid #ccc;

margin-bottom: .2rem;

overflow: hidden;

}

 

.w115 {

width: 130%;

 

}

 

.package {

height: 4rem;

-webkit-transition: all 0.3s linear;

transition: all 0.3s linear;

}

 

.lefti {

width: 15%;

height:4rem;

position: absolute;

top: 0;

left: 0;

}

 

.leftimg {

display: block;

font-style: normal;

margin: 1.3rem auto;

height: 1.7rem;

width: 1.7rem;

border: .01rem solid #435057;

background: #99beee;

border-radius: 50%;

line-height: 1.7rem;

font-size: .13rem;

color: #7a95a3;

text-align: center;

}

 

.text {

position: absolute;

top: 0;

left: 15%;

width: 74%;

height: 4rem;

color: #7a95a3;

font-family: "幼圆";

font-size: .22rem;

line-height: 4rem;

}

 

.delete {

position: absolute;

top: 0;

right: -45%;

width: 45%;

-webkit-transition: all 0.5s linear;

transition: all 0.3s linear;

}

.biao1{

float:left;

font-size: .22rem;

text-align: center;

line-height: 4rem;

color: #fff;

width:48%;

height: 4rem;

background: #ccc;

-webkit-transition: all 0.9s linear;

transition: all 0.9s linear;

}

.del1{

float:left;

font-size: .22rem;

text-align: center;

line-height: 4rem;

color: #fff;

width:30%;

height: 4rem;

background: red;

-webkit-transition: all 0.9s linear;

transition: all 0.9s linear;

}

.delete1 {

position: absolute!important;

top: 0!important;

right: -35%!important;

width:15%!important;

font-size: .22rem!important;

text-align: center!important;

line-height: 4rem!important;

color: #fff!important;

height: 4rem!important;

background: red!important;

-webkit-transition: all 0.9s linear!important;

transition: all 0.9s linear!important;

}

.swipeleft {

-webkit-transition: all 0.9s linear;

transition: all 0.9s linear;

transform: translateX(-35%);

-webkit-transform: translateX(-35%);

}

.pan{

position:absolute;right:10px;line-height:4rem;color:rgb(138, 145, 145);

}

.swiperight {

-webkit-transition: all 0.9s linear;

transition: all 0.9s linear;

transform: translateX(0%);

-webkit-transform: translateX(0%);

}

</style>

</head>

 

<body>

 

<div class="contents ">

<div class="package w115">

<div class="lefti">

<i class="leftimg">左滑</i>

</div>

<div class="text">左滑显示删除按钮左滑显示删除按钮</div><span class="pan">13:00</span>

<div class="delete delete1">删除

<!-- <div class="biao1">标记成未读</div> -->

<!-- <div class="del1 del2">删除</div> -->

</div>

</div>

</div>

 

<div class="contents ">

<div class="package w115">

<div class="lefti">

<i class="leftimg">左滑</i>

</div>

<div class="text">左滑显示删除按钮左滑显示删除按钮</div><span class="pan">13:00</span>

<div class="delete">

<div class="biao1">标记成未读</div>

<div class="del1">删除</div>

</div>

</div>

</div>

 

<div class="contents ">

<div class="package w115">

<div class="lefti">

<i class="leftimg">左滑</i>

</div>

<div class="text">左滑显示删除按钮左滑显示删除按钮</div><span class="pan">13:00</span>

<div class="delete">

<div class="biao1">标记成未读</div>

<div class="del1">删除</div>

</div>

</div>

</div>

 

<script>

var expansion = null; //是否存在展开的contents

var container = document.querySelectorAll('.contents .package');//找到所有的左滑盒子

for (var index = 0; index < container.length; index++) {

var x, y, X, Y, swipeX, swipeY;

//监听左滑盒子的触摸事件

container[index].addEventListener('touchstart', function (event) {

//获取触摸点的坐标targetTouches[0].pageX,Y 

x = event.changedTouches[0].pageX;

y = event.changedTouches[0].pageY;

swipeX = true;

swipeY = true;

if (expansion) {

//判断是否展开,如果展开则收起

expansion.className = "swiperight";

}

});

//监听左滑盒子的屏幕上滑动事件 touchmove事件:当手指在屏幕上滑动的时候连续地触发。在这个事件发生期间,调用preventDefault()事件可以阻止滚动。

container[index].addEventListener('touchmove', function (event) {

X = event.changedTouches[0].pageX;

Y = event.changedTouches[0].pageY;

//console.log(X,Y);

//判断左右滑动

if (swipeX && Math.abs(X - x) - Math.abs(Y - y) > 0) {

// 阻止事件冒泡

event.stopPropagation();

if (X - x > 10) {   //右滑

event.preventDefault();  // 取消事件的默认动作

this.className = "swiperight";

}

if (x - X > 10) {   //左滑

event.preventDefault();

this.className = "swipeleft";   //左滑展开

expansion = this;

}

swipeY = false;

}

// 上下滑动

if (swipeY && Math.abs(X - x) - Math.abs(Y - y) < 0) {

swipeX = false;

}

})

}

</script>

</body>

 

</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值