Home >Web Front-end >H5 Tutorial >HTML5 touch event realizes the effect of sliding the page up and down [with code]_html5 tutorial skills

HTML5 touch event realizes the effect of sliding the page up and down [with code]_html5 tutorial skills

WBOY
WBOYOriginal
2016-05-16 15:51:392314browse

html5 touch event realizes the effect of sliding the page up and down [with code]

XML/HTML CodeCopy content to clipboard
  1. >    
  2. <html lang="en">    
  3. <head>    
  4. <meta charset="UTF-8">    
  5. <meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0"/>    
  6. <title>2014-4-29title>    
  7. <style>    
  8. * {margin: 0; padding: 0;}    
  9. #outer{ width:90%; height: 490px; background: #000; margin: auto; overflow: hidden;}    
  10. #inner{width:80%; height: 2000px; background: #f67d42; margin: auto; position:relative; top:0; }    
  11. style>    
  12. <script src='jquery-1.9.1.min.js'>script>    
  13. head>    
  14. <body>    
  15.   
  16. <div id="spText">div>    
  17. <div id="outer">    
  18. <div id="inner">    
  19. 123<br> 123<br> gag<br> af<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> yryyr<br> ryry<br> 123<br> 123<br> 123<br> 123<br> 123<br> sdff<br> fef<br> 123<br> hr<br> hrh<br> 5y<br> 123<br> er<br> ert<br> 123<br> rgdgdg<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> gfgfgfgfgfgf<br> sdsdsdsdsdsd<br> sf<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> gdggdgdg<br> 123<br> drgdrgd<br> 123<br> 123<br> 123<br> yuyuyuyuyuy<br> hjkhjkhkhkhjkhkh<br> kjkjk<br>123<br> 123<br> gag<br> af<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> yryyr<br> ryry<br> 123<br> 123<br> 123<br> 123<br> 123<br> sdff<br> fef<br> 123<br> hr<br> hrh<br> 5y<br> 123<br> er<br> ert<br> 123<br> rgdgdg<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> gfgfgfgfgfgf<br> sdsdsdsdsdsd<br> sf<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> 123<br> gdggdgdg<br> 123<br> drgdrgd<br> 123<br> 123<br> 123<br> yuyuyuyuyuy<br> hjkhjkhkhkhjkhkh<br> kjkjk<br>    
  20. div>    
  21. div>    
  22.   
  23. <script>    
  24. var startX,//触摸时的坐标    
  25. startY, 
  26. x, //sliding distance
  27. y,
  28. aboveY=0; //Set a global variable to record the position of the last internal block slide
  29. var inner=document.getElementById("inner");
  30. function touchSatrt(e){//touch
  31. e.preventDefault();
  32. var touch=e.touches[0];
  33. startY = touch.pageY; //Coordinates when just touched
  34. }
  35. function touchMove(e){//Slide
  36. e.preventDefault();
  37. var touch = e.touches[0];
  38. y = touch.pageY - startY;//Sliding distance
  39. //inner.style.webkitTransform = 'translate(' 0 'px, ' y 'px )'; //You can also use css3 method
  40. inner.style.top=aboveY y "px"; //In this sentence  
  41. }
  42. function touchEnd(e){//Finger leaves the screen
  43. e.preventDefault();
  44. aboveY=parseInt(inner.style.top);//Record the internal slider after the touch ends The sliding position is reflected in the global variable and must be converted into an integer using parseInt();
  45. }//
  46. document.getElementById("outer").addEventListener('touchstart', touchSatrt,false);
  47. document.getElementById("outer").addEventListener('touchmove', touchMove,false);
  48. document.getElementById("outer").addEventListener('touchend', touchEnd,false);
  49. script> 
  50. body> 
  51. html>

The above html5 touch event realizes the page sliding up and down effect [with code] is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

Original text: http://www.tuicool.com/articles/nIBJju

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn