Moving End sliding frame

Source: Internet
Author: User

Html:

<! DOCTYPE html>


<script src= "Js/v.js" ></script>
<script src= "Js/jquery-2.1.1.min.js" ></script>
<link rel= "stylesheet" href= "Css/main.css" >
<script src= "Js/main.js" ></script>
<meta charset= "UTF-8"/>
<title></title>

<body>
<div id= "Container" >
<div id= "Next" class= "Next" ></div>
<div id= "Music" ></div>
<div id= "Wrap" >
<!--first page--
<div class= "page" id= "P0" >
</div>
<!--page two--
<div class= "page" id= "P1" >
</div>
<!--third Page--
<div class= "page" id= "P2" >
</div>
<!--page fourth--
<div class= "page" id= "P3" >
</div>
<!--page fifth--
<div class= "page" id= "P4" >
</div>
</div>
</div>
<audio id= "MP3" src= "Mp3/bg.mp3" autoplay= "true" loop>
</audio>
</body>

Css:

@charset "Utf-8";
Html,body{margin:0;width:100%;height:100%;overflow:hidden;}
body{
width:100%;
Overflow:hidden;
Background: #000;
}
#container {
width:100%;
height:100%;
Overflow:hidden;
}
#wrap {
width:100%;
height:100%;
}
. page{
position:relative;
Float:left;
width:100%;
Overflow:hidden;
Background-position:center;
Background-repeat:no-repeat;
}
#music {position:absolute; width:44px; height:44px; right:30px; top:80px; Background:url (...) /img/music.png) No-repeat; z-index:999;}
#p0 {background: #f00;}
#p1 {background: #0f0;}
#p2 {background: #00f;}
#p3 {background: #ff0;}
#p4 {background: #0ff;}
#p5 {background: #f0f;}

Js:

$ (function () {
$ (document.body). bind (' Touchmove ', function (event) {
Event.preventdefault ();
});
Get screen height
var sh = window.innerheight;
Page height is screen height
$ (". Page"). Height (SH);
Get page Count
var s = $ (". Page"). Length;
var ey = 0;//
var cur = 0;
var dy, CT;
var OS = $, ts = 30;//slide more than OS pixels or interval time is less than DT
Touch events
var Mytouchele = document.getElementById ("wrap");
Mytouchele.addeventlistener ("Touchstart", Touchstart, false);
Mytouchele.addeventlistener ("Touchmove", Touchmove, false);
Mytouchele.addeventlistener ("Touchend", Touchend, false);
function Touchstart (e) {
ct = new Date (). GetTime ();
EY = E.touches[0].pagey;
};
function TouchMove (e) {
E.preventdefault ();
dy = E.touches[0].pagey;
if (cur = = 0 && dy > ey) {return false;}
if (cur = = s-1 &&-cur * SH-(Ey-dy) < Sh-s * sh) {return false;}
$ ("#wrap"). CSS ({
MarginTop:-cur * SH-(Ey-dy) + "px"
});
};
function Touchend (e) {
Console.log (cur);
DT = new Date (). GetTime ()-CT;
if (dy = = 0) {return false;}
if (Dy-ey <-os | | (Dy-ey < 0 && DT < ts)) {
DY = 0;
Go_down ();
return false;
}
if (Dy-ey > OS | | (Dy-ey > 0 && dt < ts)) {
DY = 0;
Go_up ();
return false;
}
DY = 0;
Slide (cur);

}
Performing a slide animation
function Slide (x) {
$ ("#wrap"). Animate ({
MarginTop:-X * sh + "px"
}, "Fast");
cur = x;
Bind (cur);
}
Swipe up
function Go_up () {
if (cur > 0) {
Slide (cur-1);
}else{
Slide (cur);
}
}
Swipe down
function Go_down () {
if (cur < s-1) {
Slide (cur + 1);
}else{
Slide (cur);
}

}
Bind (0);
$ ("#music"). AddClass ("Music");
function bind (cur)
{
if (cur==0) {

}else if (cur==1) {

}else if (cur==2) {

}else if (cur==3) {

}else if (cur==4) {

}else if (cur==5) {

}
}
Music events
var Plays=document.getelementbyid ("MP3");
$ ("#music"). Bind ("Touchstart", function () {
if (plays.paused) {
Plays.play ();
$ ("#music"). AddClass ("Music");
}else{
Plays.pause ();
$ ("#music"). Removeclass ("Music");
}
})
});

Moving End sliding frame

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.