<! DOCTYPE html>
<script>
(function () {
function SetFont () {
document.documentelement.style.fontsize=document.documentelement.clientwidth/16+ ' px ';
}
SetFont ();
Window.addeventlistener (' resize ', setfont,false)
})();
</script>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" >
<meta name= "apple-mobile-web-app-capable" content= "yes" >
<meta name= "Apple-mobile-web-app-status-bar-style" content= "Black" >
<title>Document</title>
<style>
*{
margin:0;
padding:0;
List-style:none;
}
html,body{
width:100%;
}
#box {
width:100%;
}
#sec {
width:100%;
}
#flesh {
width:100%;
height:0;
Overflow:hidden;
Text-align:center;
}
#tab {
width:100%;
Overflow:hidden;
}
#pic {
width:700%;
Display:-webkit-box;
}
#pic li{
-webkit-box-flex:1;
Height:8.5rem;
}
#pic Li img{
width:100%;
height:100%;
}
</style>
<script>
Window.addeventlistener (' domcontentloaded ', function () {
var Op=document.getelementbyid (' pic ');
var Ali=op.children;
var inow=1;
var dir= ';
var Bok=false;
var timer;
var x=-inow*ali[0].offsetwidth;
Op.style.webkittransform= ' TranslateX (' +x+ ' px) ';
Op.addeventlistener (' Touchstart ', function (EV) {//1. Write basic Drag first
if (BOK) return;//If drag too fast will lead to grin so use the switch to limit the drag state with the motion state monitoring only to listen to the completion of the movement to continue to drag the difficulty is when the lock is the Bok=true 1. When the mouse point is true (locked) If you just click and not drag it will be locked but the motion can not be detected by the end of the movement to unlock (bok=false) and then can not continue to drag at the same time click on the lock will occur after the return of the event can not be executed 2. When you're moving, you lock it down, but not drag it around. is to drag up and down the words will also cause can not be unlocked, so only when the exercise to determine whether to drag the left and right when determined to drag around the time is locked is bok=true
Op.style.webkittransition= ' none ';//each move will have a transition state, so you need to kill the transition state when you click.
Clearinterval (timer)
var Startx=ev.targettouches[0].pagex;
var Starty=ev.targettouches[0].pagey;
var disx=startx-x;
function Move (EV) {
var Movex=ev.targettouches[0].pagex;
var Movey=ev.targettouches[0].pagey;
if (dir) {//4. Slide lock minus the initial coordinate value with the moved coordinate value first dir is empty go else
if (dir== ' l2r ') {
Bok=true;
X=MOVEX-DISX;
}
}else{
if (Math.Abs (MOVEX-STARTX) >10) {//If the horizontal drag is greater than a value, the decision is to drag it horizontally and then return to if and the DIR=L2R is set up to assign a value to the displacement x so that it can only be dragged horizontally
Dir= ' L2R ';
}else if (Math.Abs (movey-starty) >10) {
Dir= ' T2B '
}
}
Op.style.webkittransition= ' 0.5s all ease ';
Op.style.webkittransform= ' TranslateX (' +x+ ' px) ';
}
function End (EV) {
Document.removeeventlistener (' Touchmove ', move,false);
Document.removeeventlistener (' Touchend ', end,false);
if (dir== ' l2r ') {
if (Math.Abs (EV.CHANGEDTOUCHES[0].PAGEX-STARTX) >50) {//2. If the left/right displacement is greater than 50, the mouse is released automatically.
if (ev.changedtouches[0].pagex-startx>0) {
inow--;
}else if (ev.changedtouches[0].pagex-startx<0) {
inow++;
}
}
}
Op.style.webkittransition= ' 0.5s all ease ';
X=-inow*ali[0].offsetwidth;
Op.style.webkittransform= ' TranslateX (' +x+ ' px) ';
Dir= ";
Timer=setinterval (function () {
inow++;
Op.style.webkittransition= ' 0.5s all ease ';
if (inow==ali.length) {
Inow=1;
Op.style.webkittransition= ' None ';
}
X=-inow*ali[0].offsetwidth;
Op.style.webkittransform= ' TranslateX (' +x+ ' px) ';
},1000)
}
Document.addeventlistener (' Touchmove ', move,false);
Document.addeventlistener (' Touchend ', end,false)
Ev.preventdefault ();
},false)
Op.addeventlistener (' Transitionend ', function () {//3. Monitor the motion status and make a inow judgment after the monitoring is complete.
Bok=false;
if (inow==0) {
Inow=ali.length-2
}
if (inow==ali.length-1) {
Inow=1
}
Op.style.webkittransition= ' none ';//instantly drag and drop back to no motion state
X=-inow*ali[0].offsetwidth;
Op.style.webkittransform= ' TranslateX (' +x+ ' px) ';
},false)
Timer=setinterval (function () {
inow++;
Op.style.webkittransition= ' 0.5s all ease ';
if (inow==ali.length) {
inow=1;
Op.style.webkittransition= ' None ';
}
X=-inow*ali[0].offsetwidth;
Op.style.webkittransform= ' TranslateX (' +x+ ' px) ';
},1000)
//5. Write loading status drag-and-drop
var Osec=document.getelementbyid (' sec ');
var Oflesh=document.getelementbyid (' flesh ');
Var y=0;
Osec.addeventlistener (' Touchstart ', function (EV) {
oflesh.style.webkittransition= ' none ';// Each move has a transition state webkittransition so when clicked, kill the last transition state
Var starty=ev.targettouches[0].pagey;
var disy=starty-y;
Function Move (EV) {
var movey=ev.targettouches[0].pagey;
Y=movey-disy;
if (dir== ' t2b ') {//determines that the assignment is only given when dragging up or down
if (y>=100) {
y=100;
}
oflesh.style.webkittransition= ' 0.5s all ease '
oflesh.style.height=y+ ' px ';
}
}
Function End () {
Document.removeeventlistener (' Touchmove ', move,false);
Document.removeeventlistener (' Touchend ', end,false);
oflesh.style.height=0+ ' px ';//release the mouse back to its original state
}
Document.addeventlistener (' Touchmove ', move,false);
Document.addeventlistener (' Touchend ', end,false);
Ev.preventdefault ();
},false)
},false)
</script>
<body>
<section id= "box" >
<section id= "SEC" >
<div id= "Flesh" >
</div>
<section id= "tab" >
<ul id= "pic" >
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</section>
</section>
</section>
</body>
Seamless scrolling + drop-down refresh + directional swipe on mobile