Moving side Slide

Source: Internet
Author: User

<! DOCTYPE html>


<meta charset= "UTF-8" >
<meta name= "viewport" id= "viewport" content= "Width=device-width, initial-scale=1" >
&LT;TITLE&GT;HTML5 Swipe left to delete effects </title>
<style>
* {
padding:0;
margin:0;
List-style:none;
}

Header {
Background: #f7483b;
BORDER-BOTTOM:1PX Solid #ccc
}

Header H2 {
Text-align:center;
line-height:54px;
font-size:16px;
Color: #fff
}

. list-ul {
Overflow:hidden
}

. list-li {
line-height:60px;
border-bottom:1px solid #fcfcfc;
position:relative;
Padding:0 12px;
Color: #666;
Background: #f2f2f2;
-webkit-transform:translatex (0px);
}

. btn {
Position:absolute;
top:0;
Right: -80px;
Text-align:center;
Background: #ffcb20;
Color: #fff;
width:80px
}
</style>
<script>
/*
* Description: HTML5 Apple phone swipe left to delete effects
*/
Window.addeventlistener (' Load ', function () {
var Initx; Touch position
var MoveX; Position when sliding
var X = 0; Moving distance
var objx = 0; Target object Location
Window.addeventlistener (' Touchstart ', function (event) {
Event.preventdefault ();
var obj = Event.target.parentNode;
if (Obj.classname = = "List-li") {
INITX = Event.targettouches[0].pagex;
OBJX = (Obj.style.WebkitTransform.replace (/translatex\ (/g, ""). Replace (/px\)/g, "")) * 1;
}
if (OBJX = = 0) {
Window.addeventlistener (' Touchmove ', function (event) {
Event.preventdefault ();
var obj = Event.target.parentNode;
if (Obj.classname = = "List-li") {
MoveX = Event.targettouches[0].pagex;
X = MOVEX-INITX;
if (X >= 0) {
Obj.style.WebkitTransform = "TranslateX (" + 0 + "px)";
} else if (X < 0) {
var L = math.abs (X);
Obj.style.WebkitTransform = "TranslateX (" +-L + "px)";
if (L > 80) {
L = 80;
Obj.style.WebkitTransform = "TranslateX (" +-L + "px)";
}
}
}
});
} else if (OBJX < 0) {
Window.addeventlistener (' Touchmove ', function (event) {
Event.preventdefault ();
var obj = Event.target.parentNode;
if (Obj.classname = = "List-li") {
MoveX = Event.targettouches[0].pagex;
X = MOVEX-INITX;
if (X >= 0) {
var r = -80 + Math.Abs (X);
Obj.style.WebkitTransform = "TranslateX (" + R + "px)";
if (R > 0) {
R = 0;
Obj.style.WebkitTransform = "TranslateX (" + R + "px)";
}
} else {//swipe left
Obj.style.WebkitTransform = "TranslateX (" + -80 + "px)";
}
}
});
}

})
Window.addeventlistener (' Touchend ', function (event) {
Event.preventdefault ();
var obj = Event.target.parentNode;
if (Obj.classname = = "List-li") {
OBJX = (Obj.style.WebkitTransform.replace (/translatex\ (/g, ""). Replace (/px\)/g, "")) * 1;
if (Objx >-40) {
Obj.style.WebkitTransform = "TranslateX (" + 0 + "px)";
OBJX = 0;
} else {
Obj.style.WebkitTransform = "TranslateX (" + -80 + "px)";
OBJX =-80;
}
}
})
})
</script>

<body>


<section>
<ul class= "List-ul" >
<li class= "List-li" >
<div>
Your courier is here, please sign downstairs.
</div>
<div class= "btn" > Delete </div>
</li>
<li class= "List-li" >
<div>
Whoa, what are you doing, come on, just wait for you.
</div>
<div class= "btn" > Delete </div>
</li>
</ul>
</section>
</body>

Moving side Slide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.