当前位置:Gxlcms > JavaScript > js仿小米手机上下滑动效果

js仿小米手机上下滑动效果

时间:2021-07-01 10:21:17 帮助过:5人阅读

本文实例为大家分享了js上下滑动效果的具体代码,供大家参考,具体内容如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <style>
  7. .box{
  8. width: 512px;
  9. height: 400px;
  10. margin:100px auto;
  11. overflow: hidden;
  12. position: relative;
  13. border: 1px solid red;
  14. }
  15. .box img{
  16. position: absolute;
  17. left: 0;
  18. top: 0;
  19. }
  20. .box div{
  21. width: 512px;
  22. height: 200px;
  23. position: absolute;
  24. left: 0;
  25. }
  26. .up{
  27. top:0;
  28. }
  29. .down{
  30. top: 200px;
  31. }
  32. </style>
  33. <script>
  34. window.onload = function(){
  35. function $(id){ return document.getElementById(id);}
  36. var num = 0;
  37. var timer;
  38. var timer1;
  39. $("picup").onmouseover = function(){ //往下走
  40. timer = setInterval(function(){
  41. if(num>=0){
  42. clearInterval(timer);
  43. }else{
  44. num+=3;
  45. $("pic").style.top = num +"px";
  46. }
  47. },10);
  48. }
  49. $("picup").onmouseleave = function(){
  50. clearInterval(timer);
  51. }
  52. $("picdown").onmouseover = function(){ //往上走
  53. timer1 = setInterval(function(){
  54. if(num <= -1070){
  55. clearInterval(timer1);
  56. }else{
  57. num-=3;
  58. $("pic").style.top = num +"px";
  59. }
  60. },30);
  61. }
  62. $("picdown").onmouseleave = function(){
  63. clearInterval(timer1);
  64. }
  65. }
  66. </script>
  67. </head>
  68. <body>
  69. <div class="box">
  70. <img src="mi.png" alt="" id="pic">
  71. <div class="up" id="picup"></div>
  72. <div class="down" id="picdown"></div>
  73. </div>
  74. </body>
  75. </html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

人气教程排行