zepto -> implement sliding page turning

 

zepto official network: http://www.zeptojs.cn/#download

All code includes various plugins

https://github.com/madrobby/zepto

Where fx.js is the animate animation plugin must

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no"  />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name='apple-touch-fullscreen' content='yes'/>
	<meta name="full-screen" content="yes"/>
	<script src="./zepto.min.js" type="text/javascript"></script>
	<script src="./touch.js" type="text/javascript"></script>
	<script src="./fx.js" type="text/javascript"></script>
	
    <title>zepto swipe to page</title>
	<style type="text/css">
		*{margin:0px;padding:0px;font-size:15px;font-weight:normal;list-style: none;font-family:"微软雅黑";-webkit-user-select:none;}
		html,body{width:100%;height:100%;}
		.smooth_scroll{-webkit-overflow-scrolling: touch;}
		.main_prt{width:100%;overflow:hidden;}
		.big_prt{width:200%;height:100%;}	
		.page1{width:50%;height:100%;overflow-x:hidden;overflow-y:auto;float:left;background:#eee}
		.page2{width:50%;height:100%;overflow-x:hidden;overflow-y:auto;float:left;background:#ddd}
	</style>
</head>
<body style="text-align:center;transform:translateX(0);">
<div class="main_prt">
	<div class="big_prt">
		<div class="page1 smooth_scroll">
			Through this incident, Duan Xufeng (left) and Wang Kun (right) became good friends. Dahe Newspaper
				A month ago, a fire broke out in the house of Wang Kun, who lives in the Municipal Party Committee Family Court on Gongmao Road, Shangqiu City, Henan Province. Duan Xufeng, a 65-year-old neighbor, hurried to rescue when he found it. Unexpectedly, the exploding glass fragments injured Duan Xufeng's left arm.
				Afterwards, Wang Kun and his wife felt guilty. They offered 10,000 yuan in cash to compensate Duan Xufeng, but Duan Xufeng's family refused. Later, they secretly paid 10,000 yuan for his medical expenses. What Wang Kun and his wife did not expect was that Duan Xufeng returned the 10,000 yuan to the two after he was discharged from the hospital.
				Duan Xufeng told The Paper (www.thepaper.cn) on November 3: "Wang Kun's house has been burned down, and everything needs to be re-purchased. Compared to me, they need this 10,000 yuan more, not to mention firefighting. I do it voluntarily."
				【dialogue】
				The Paper: How is the recovery from the injury?
				Duan Xufeng: He has recovered very well. After being discharged from the hospital, he was undergoing physiotherapy and acupuncture, and the plaster was removed, but now his hands cannot hold things as normally as before.
				The Paper: When you found out that your neighbor's house was on fire, was the fire big?
				Duan Xufeng: There were three houses on fire. When I saw the fire, the east house was on fire. The fire had already burned to the second floor, and it was still very big from the outside.
				The Paper: Did you not consider your own safety before rushing into the fire?
				Duan Xufeng: I didn't have time to think about it. I hurriedly woke up the other neighbors and informed them of the fire. Later, I ran to Wang Kun's house and saw that the back door of his house was still open, so I went in to see if there was anyone inside. I saw someone in the anti-theft window leaning on the window and breathing heavily. When I looked closely, it was Wang Kun. Then I pried open the security window and rescued Wang Kun.
				The Paper: How did you get hurt?
				Duan Xufeng: After I rescued Wang Kun, I asked him where there was a water source. He said that there was a water pipe several meters long in the yard. I took one end of the water pipe and fixed it to the faucet to prevent it from falling. Wang Kun took the other end of the water pipe to put out the fire.
				A month ago, a fire broke out in the house of Wang Kun, who lives in the Municipal Party Committee Family Court on Gongmao Road, Shangqiu City, Henan Province. Duan Xufeng, a 65-year-old neighbor, hurried to rescue when he found it. Unexpectedly, the exploding glass fragments injured Duan Xufeng's left arm.
				Afterwards, Wang Kun and his wife felt guilty. They offered 10,000 yuan in cash to compensate Duan Xufeng, but Duan Xufeng's family refused. Later, they secretly paid 10,000 yuan for his medical expenses. What Wang Kun and his wife did not expect was that Duan Xufeng returned the 10,000 yuan to the two after he was discharged from the hospital.
				Duan Xufeng told The Paper (www.thepaper.cn) on November 3: "Wang Kun's house has been burned down, and everything needs to be re-purchased. Compared to me, they need this 10,000 yuan more, not to mention firefighting. I do it voluntarily."
				【dialogue】
				The Paper: How is the recovery from the injury?
				Duan Xufeng: He has recovered very well. After being discharged from the hospital, he is undergoing physiotherapy, acupuncture and plaster casts.
				Duan Xufeng: There were three houses on fire. When I saw the fire, the east house was on fire. The fire had already burned to the second floor, and it was still very big from the outside.
				The Paper: Did you not consider your own safety before rushing into the fire?
				Duan Xufeng: I didn't have time to think about it. I hurriedly woke up the other neighbors and informed them of the fire. Later, I ran to Wang Kun's house and saw that the back door of his house was still open, so I went in to see if there was anyone inside. I saw someone in the anti-theft window leaning on the window and breathing heavily. When I looked closely, it was Wang Kun. Then I pried open the security window and rescued Wang Kun.
				The Paper: How did you get hurt?
				Duan Xufeng: After I rescued Wang Kun, I asked him where there was a water source. He said that there was a water pipe several meters long in the yard. I took one end of the water pipe and fixed the water pipe to the faucet to prevent it from falling. Wang Kun, who was holding the water pipe, caught fire in the house of Wang Kun, a 65-year-old neighbor, Duan Xufeng. When you find it, go to the rescue. Unexpectedly, the exploding glass fragments injured Duan Xufeng's left arm.
				Afterwards, Wang Kun and his wife felt guilty. They offered 10,000 yuan in cash to compensate Duan Xufeng, but Duan Xufeng's family refused. Later, they secretly paid 10,000 yuan for his medical expenses. What Wang Kun and his wife did not expect was that Duan Xufeng returned the 10,000 yuan to the two after he was discharged from the hospital.
				Duan Xufeng told The Paper (www.thepaper.cn) on November 3: "Wang Kun's house has been burned down, and everything needs to be re-purchased. Compared to me, they need this 10,000 yuan more, not to mention firefighting. I do it voluntarily."
				【dialogue】
				The Paper: How is the recovery from the injury?
				Duan Xufeng: He has recovered very well. After being discharged from the hospital, he is undergoing physiotherapy, acupuncture and plaster casts.
				Duan Xufeng: There were three houses on fire. When I saw the fire, the east house was on fire. The fire had already burned to the second floor, and it was still very big from the outside.
				The Paper: Did you not consider your own safety before rushing into the fire?
				Duan Xufeng: I didn't have time to think about it. I hurriedly woke up the other neighbors and informed them of the fire. Later, I ran to Wang Kun's house and saw that the back door of his house was still open, so I went in to see if there was anyone inside. I saw someone inside the security window where there was a water source. He said that there was a water pipe several meters long in the yard. I took one end of the water pipe and fixed it to the faucet to prevent it from falling. Wang Kun took the other end of the water pipe to put out the fire. At this point, the glass exploded with fire, and the shards fell on my left arm.
		</div>
		<div class="page2 smooth_scroll">
			Through this incident, Duan Xufeng (left) and Wang Kun (right) became good friends. Dahe Newspaper
				A month ago, a fire broke out in the house of Wang Kun, who lives in the Municipal Party Committee Family Court on Gongmao Road, Shangqiu City, Henan Province. Duan Xufeng, a 65-year-old neighbor, hurried to rescue when he found it. Unexpectedly, the exploding glass fragments injured Duan Xufeng's left arm.
				Afterwards, Wang Kun and his wife felt guilty. They offered 10,000 yuan in cash to compensate Duan Xufeng, but Duan Xufeng's family refused. Later, they secretly paid 10,000 yuan for his medical expenses. What Wang Kun and his wife did not expect was that Duan Xufeng returned the 10,000 yuan to the two after he was discharged from the hospital.
				Duan Xufeng told The Paper (www.thepaper.cn) on November 3: "Wang Kun's house has been burned down, and everything needs to be re-purchased. Compared to me, they need this 10,000 yuan more, not to mention firefighting. I do it voluntarily."
				【dialogue】
				The Paper: How is the recovery from the injury?
				Duan Xufeng: He has recovered very well. After being discharged from the hospital, he was undergoing physiotherapy and acupuncture, and the plaster was removed, but now his hands cannot hold things as normally as before.
				The Paper: When you found out that your neighbor's house was on fire, was the fire big?
				Duan Xufeng: There were three houses on fire. When I saw the fire, the east house was on fire. The fire had already burned to the second floor, and it was still very big from the outside.
				The Paper: Did you not consider your own safety before rushing into the fire?
				Duan Xufeng: I didn't have time to think about it. I hurriedly woke up the other neighbors and informed them of the fire. Later, I ran to Wang Kun's house and saw that the back door of his house was still open, so I went in to see if there was anyone inside. I saw someone in the anti-theft window leaning on the window and breathing heavily. When I looked closely, it was Wang Kun. Then I pried open the security window and rescued Wang Kun.
				The Paper: How did you get hurt?
				Duan Xufeng: After I rescued Wang Kun, I asked him where there was a water source. He said that there was a water pipe several meters long in the yard. I took one end of the water pipe and fixed it to the faucet to prevent it from falling. Wang Kun took the other end of the water pipe to put out the fire.
				A month ago, a fire broke out in the house of Wang Kun, who lives in the Municipal Party Committee Family Court on Gongmao Road, Shangqiu City, Henan Province. Duan Xufeng, a 65-year-old neighbor, hurried to rescue when he found it. Unexpectedly, the exploding glass fragments injured Duan Xufeng's left arm.
				Afterwards, Wang Kun and his wife felt guilty. They offered 10,000 yuan in cash to compensate Duan Xufeng, but Duan Xufeng's family refused. Later, they secretly paid 10,000 yuan for his medical expenses. What Wang Kun and his wife did not expect was that Duan Xufeng returned the 10,000 yuan to the two after he was discharged from the hospital.
				Duan Xufeng told The Paper (www.thepaper.cn) on November 3: "Wang Kun's house has been burned down, and everything needs to be re-purchased. Compared to me, they need this 10,000 yuan more, not to mention firefighting. I do it voluntarily."
				【dialogue】
				The Paper: How is the recovery from the injury?
				Duan Xufeng: He has recovered very well. After being discharged from the hospital, he is undergoing physiotherapy, acupuncture and plaster casts.
				Duan Xufeng: There were three houses on fire. When I saw the fire, the east house was on fire. The fire had already burned to the second floor, and it was still very big from the outside.
				The Paper: Did you not consider your own safety before rushing into the fire?
				Duan Xufeng: I didn't have time to think about it. I hurriedly woke up the other neighbors and informed them of the fire. Later, I ran to Wang Kun's house and saw that the back door of his house was still open, so I went in to see if there was anyone inside. I saw someone in the anti-theft window leaning on the window and breathing heavily. When I looked closely, it was Wang Kun. Then I pried open the security window and rescued Wang Kun.
				The Paper: How did you get hurt?
				Duan Xufeng: After I rescued Wang Kun, I asked him where there was a water source. He said that there was a water pipe several meters long in the yard. I took one end of the water pipe and fixed the water pipe to the faucet to prevent it from falling. Wang Kun, who was holding the water pipe, caught fire in the house of Wang Kun, a 65-year-old neighbor, Duan Xufeng. When you find it, go to the rescue. Unexpectedly, the exploding glass fragments injured Duan Xufeng's left arm.
				Afterwards, Wang Kun and his wife felt guilty. They offered 10,000 yuan in cash to compensate Duan Xufeng, but Duan Xufeng's family refused. Later, they secretly paid 10,000 yuan for his medical expenses. What Wang Kun and his wife did not expect was that Duan Xufeng returned the 10,000 yuan to the two after he was discharged from the hospital.
				Duan Xufeng told The Paper (www.thepaper.cn) on November 3: "Wang Kun's house has been burned down, and everything needs to be re-purchased. Compared to me, they need this 10,000 yuan more, not to mention firefighting. I do it voluntarily."
				【dialogue】
				The Paper: How is the recovery from the injury?
				Duan Xufeng: He has recovered very well. After being discharged from the hospital, he is undergoing physiotherapy, acupuncture and plaster casts.
				Duan Xufeng: There were three houses on fire. When I saw the fire, the east house was on fire. The fire had already burned to the second floor, and it was still very big from the outside.
				The Paper: Did you not consider your own safety before rushing into the fire?
				Duan Xufeng: I didn't have time to think about it. I hurriedly woke up the other neighbors and informed them of the fire. Later, I ran to Wang Kun's house and saw that the back door of his house was still open, so I went in to see if there was anyone inside. I saw someone inside the security window where there was a water source. He said that there was a water pipe several meters long in the yard. I took one end of the water pipe and fixed it to the faucet to prevent it from falling. Wang Kun took the other end of the water pipe to put out the fire. At this point, the glass exploded with fire, and the shards fell on my left arm.
	 
		<div style="clear:both;width:100%;height:0px;overflow:hidden"></div>
	</div>
</div>
<script language="javascript">
<!--
	var touchStartX = 0;
	var touchMoveX = 0;
	var isScrollinging = false;
	var canSlideHor = false;
	$(window).on('scroll',function(e){	
		isScrolling = true;
		canSlideHor = false;
	});
	$(".big_prt").on('touchstart',function(e){
		isScrolling = false;
		canSlideHor = false;
		touchStartX = e.touches[0].clientX;
		touchMoveX = 0;
	});
	$(".big_prt").on('touchmove',function(e){
		touchMoveX = e.touches[0].clientX;
		if(isScrolling == true){
			return;
		}
		var goX;
		if(Math.abs(touchMoveX-touchStartX) > 20 || canSlideHor == true){
			canSlideHor = true;
			goX = ((touchMoveX-touchStartX));
			if(crtPage == 2){
				goX =  goX - windowWidth();
			}
			if(goX > 0){goX = 0;}
			if(goX < -windowWidth()){goX = -windowWidth();}		
			$(".big_prt").css("transform","translateX("+goX+"px)");
		}else{
			if(crtPage == 1){
				goX = "0px";
			}else{
				goX = "-"+windowWidth()+"px";
			}
			$(".big_prt").css("transform","translateX("+goX+"px)");
		}
	});
	var crtPage = 1;
	$(".big_prt").on('touchend',function(e){
		var doX;
		if(isScrolling == true  || touchMoveX == 0 ){		
			if(crtPage == 1){
				doX = "0px";
			}else{
				doX = "-"+windowWidth()+"px";
			}
			$(".big_prt").animate({
			  translateX: doX
			}, 100, 'ease-out');
			return;
		}
		if((touchMoveX-touchStartX) > 100){
			crtPage = 1;
		}else if((touchStartX-touchMoveX) > 100){
			crtPage = 2;
		}		
		if(crtPage == 1){
			doX = "0px";
		}else{
			doX = "-"+windowWidth()+"px";
		}
		$(".big_prt").animate({
		  translateX: doX
		}, 100, 'ease-out')
	});
	function windowWidth(){
		return $(window).width();
	}
	function windowHeight(){
		return $(window).height();
	}
 

	
 
//-->
</script>
</body>
</html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326448279&siteId=291194637
Recommended