index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport"
  6. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  7. <title></title>
  8. <script src="js/mui.min.js"></script>
  9. <link href="css/mui.min.css" rel="stylesheet"/>
  10. <script type="text/javascript" charset="utf-8">
  11. mui.init();
  12. $(function () {
  13. ScrollerTrack.Init();
  14. });
  15. var ScrollerTrack = {
  16. BodyWidth: 500, MaxValue: 300, CurrentX: 0, CurrentValue: 0,
  17. Count: 0, Init: function () {
  18. var mWidth = ScrollerTrack.BodyWidth;
  19. $(".contain").css("width", mWidth + "px");
  20. var
  21. count = ScrollerTrack.MaxValue / 50;
  22. ScrollerTrack.Count = count;
  23. var itemWidth = mWidth / count;
  24. for (var i = 0; i
  25. < count
  26. ; i++) {
  27. var span = $("" + (i + 1) * 50 + "");
  28. $(span).css("width", itemWidth + "px").css("margin-left", i * itemWidth + "px");
  29. $(".value").append(span);
  30. }
  31. ScrollerTrack.Value();
  32. }, Value: function () {
  33. var currentValue;
  34. var isMoving = false;
  35. ScrollerTrack.CurrentX = $(".track").offset().left;
  36. $(".track").mousedown(function () {
  37. var target = $(this).parent();
  38. isMoving = true;
  39. $("html,body").mousemove(function (event) {
  40. if (isMoving == false) return;
  41. var changeX = event.clientX -
  42. ScrollerTrack.CurrentX;
  43. currentValue = changeX - ScrollerTrack.CurrentX;
  44. if (changeX = ScrollerTrack.BodyWidth - 16) {
  45. $(target).find(".track").css("margin-left", ScrollerTrack.BodyWidth - 16 + "px");
  46. $(target).find(".valueC").css("width", ScrollerTrack.BodyWidth - 16 + "px");
  47. $(target).find(".show").css("margin-left",
  48. ScrollerTrack.BodyWidth - 31 + "px");
  49. $(target).find(".show").html(ScrollerTrack.MaxValue);
  50. ScrollerTrack.CurrentValue = ScrollerTrack.MaxValue;
  51. } else {
  52. $(target).find(".track").css("margin-left",
  53. changeX + "px");
  54. $(target).find(".valueC").css("width", changeX + "px");
  55. $(target).find(".show").css("margin-left",
  56. changeX - 15 + "px");
  57. var v = ScrollerTrack.MaxValue * ((changeX + 16) / ScrollerTrack.BodyWidth);
  58. $(target).find(".show").html(parseInt(v));
  59. ScrollerTrack.CurrentValue = parseInt(v);
  60. }
  61. });
  62. });
  63. $("html,body").mouseup(function () {
  64. isMoving = false;
  65. });
  66. }
  67. }
  68. </script>
  69. <style>
  70. .main {
  71. margin: 0 auto;
  72. margin-top: 100px;
  73. width: 500px;
  74. font-family: 微软雅黑;
  75. -webkit-user-select: none;
  76. }
  77. .contain {
  78. width: 500px;
  79. height: 40px;
  80. background-color: #E8E8E8;
  81. }
  82. ;
  83. .track {
  84. width: 16px;
  85. height: 46px;
  86. position: absolute;
  87. margin: -3px 0 0 0px;
  88. background-color: #2dacd1;
  89. cursor: pointer;
  90. }
  91. .valueC {
  92. height: 40px;
  93. position: absolute;
  94. margin: 0;
  95. background-color: #43BFE3;
  96. }
  97. .value
  98. span {
  99. position: absolute;
  100. text-align: right;
  101. height: 40px;
  102. line-height: 40px;
  103. color: #808080;
  104. border-right: 1px solid #dddddd;
  105. }
  106. .show {
  107. width: 45px;
  108. height: 30px;
  109. background-color: #333;
  110. color: #fff;
  111. text-align: center;
  112. line-height: 30px;
  113. position: absolute;
  114. opacity: 0.9;
  115. margin-top: -38px;
  116. margin-left: -15px;
  117. }
  118. </style>
  119. </head>
  120. <body>
  121. <div>
  122. <h1>首页</h1>
  123. <input type="range" id="slider" name="slider" min="0" max="100" step="1">
  124. </div>
  125. </body>
  126. </html>