三元财务UI

jquery.slimscroll.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*! Copyright (c) 2011 Piotr Rochala (http://rocha.la)
  2. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  3. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  4. *
  5. * Version: 1.3.0
  6. *
  7. */
  8. (function(f) {
  9. jQuery.fn.extend({
  10. slimScroll: function(h) {
  11. var a = f.extend({
  12. width: "auto",
  13. height: "250px",
  14. size: "4px",
  15. color: "#000",
  16. position: "right",
  17. distance: "1px",
  18. start: "top",
  19. opacity: 0.4,
  20. alwaysVisible: !1,
  21. disableFadeOut: !1,
  22. railVisible: !1,
  23. railColor: "#333",
  24. railOpacity: 0.2,
  25. railDraggable: !0,
  26. railClass: "slimScrollRail",
  27. barClass: "slimScrollBar",
  28. wrapperClass: "slimScrollDiv",
  29. allowPageScroll: !1,
  30. wheelStep: 20,
  31. touchScrollStep: 200,
  32. borderRadius: "7px",
  33. railBorderRadius: "7px"
  34. }, h);
  35. this.each(function() {
  36. function r(d) {
  37. if (s) {
  38. d = d ||
  39. window.event;
  40. var c = 0;
  41. d.wheelDelta && (c = -d.wheelDelta / 120);
  42. d.detail && (c = d.detail / 3);
  43. f(d.target || d.srcTarget || d.srcElement).closest("." + a.wrapperClass).is(b.parent()) && m(c, !0);
  44. // 解决 [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.
  45. // d.preventDefault && !k && d.preventDefault();
  46. k || (d.returnValue = !1)
  47. }
  48. }
  49. function m(d, f, h) {
  50. k = !1;
  51. var e = d,
  52. g = b.outerHeight() - c.outerHeight();
  53. f && (e = parseInt(c.css("top")) + d * parseInt(a.wheelStep) / 100 * c.outerHeight(), e = Math.min(Math.max(
  54. e, 0), g), e = 0 < d ? Math.ceil(e) : Math.floor(e), c.css({
  55. top: e + "px"
  56. }));
  57. l = parseInt(c.css("top")) / (b.outerHeight() - c.outerHeight());
  58. e = l * (b[0].scrollHeight - b.outerHeight());
  59. h && (e = d, d = e / b[0].scrollHeight * b.outerHeight(), d = Math.min(Math.max(d, 0), g), c.css({
  60. top: d + "px"
  61. }));
  62. b.scrollTop(e);
  63. b.trigger("slimscrolling", ~~e);
  64. v();
  65. p()
  66. }
  67. function C() {
  68. window.addEventListener ? (this.addEventListener("DOMMouseScroll", r, !1), this.addEventListener(
  69. "mousewheel", r, !1), this.addEventListener("MozMousePixelScroll", r, !1)) : document.attachEvent(
  70. "onmousewheel", r)
  71. }
  72. function w() {
  73. u = Math.max(b.outerHeight() / b[0].scrollHeight * b.outerHeight(), D);
  74. c.css({
  75. height: u + "px"
  76. });
  77. var a = u == b.outerHeight() ? "none" : "block";
  78. c.css({
  79. display: a
  80. })
  81. }
  82. function v() {
  83. w();
  84. clearTimeout(A);
  85. l == ~~l ? (k = a.allowPageScroll, B != l && b.trigger("slimscroll", 0 == ~~l ? "top" : "bottom")) : k = !1;
  86. B = l;
  87. u >= b.outerHeight() ? k = !0 : (c.stop(!0, !0).fadeIn("fast"), a.railVisible && g.stop(!0, !0).fadeIn(
  88. "fast"))
  89. }
  90. function p() {
  91. a.alwaysVisible || (A = setTimeout(function() {
  92. a.disableFadeOut && s || (x || y) || (c.fadeOut("slow"), g.fadeOut("slow"))
  93. }, 1E3))
  94. }
  95. var s, x, y, A, z, u, l, B, D = 30,
  96. k = !1,
  97. b = f(this);
  98. if (b.parent().hasClass(a.wrapperClass)) {
  99. var n = b.scrollTop(),
  100. c = b.parent().find("." + a.barClass),
  101. g = b.parent().find("." + a.railClass);
  102. w();
  103. if (f.isPlainObject(h)) {
  104. if ("height" in h && "auto" == h.height) {
  105. b.parent().css("height", "auto");
  106. b.css("height", "auto");
  107. var q = b.parent().parent().height();
  108. b.parent().css("height", q);
  109. b.css("height", q)
  110. }
  111. if ("scrollTo" in h) n = parseInt(a.scrollTo);
  112. else if ("scrollBy" in h) n += parseInt(a.scrollBy);
  113. else if ("destroy" in h) {
  114. c.remove();
  115. g.remove();
  116. b.unwrap();
  117. return
  118. }
  119. m(n, !1, !0)
  120. }
  121. } else {
  122. a.height = "auto" == a.height ? b.parent().height() : a.height;
  123. n = f("<div></div>").addClass(a.wrapperClass).css({
  124. position: "relative",
  125. width: a.width,
  126. height: a.height
  127. });
  128. b.css({
  129. width: a.width,
  130. height: a.height
  131. });
  132. var g = f("<div></div>").addClass(a.railClass).css({
  133. width: a.size,
  134. height: "100%",
  135. position: "absolute",
  136. top: 0,
  137. display: a.alwaysVisible && a.railVisible ? "block" : "none",
  138. "border-radius": a.railBorderRadius,
  139. background: a.railColor,
  140. opacity: a.railOpacity,
  141. zIndex: 90
  142. }),
  143. c = f("<div></div>").addClass(a.barClass).css({
  144. background: a.color,
  145. width: a.size,
  146. position: "absolute",
  147. top: 0,
  148. opacity: a.opacity,
  149. display: a.alwaysVisible ?
  150. "block" : "none",
  151. "border-radius": a.borderRadius,
  152. BorderRadius: a.borderRadius,
  153. MozBorderRadius: a.borderRadius,
  154. WebkitBorderRadius: a.borderRadius,
  155. zIndex: 99
  156. }),
  157. q = "right" == a.position ? {
  158. right: a.distance
  159. } : {
  160. left: a.distance
  161. };
  162. g.css(q);
  163. c.css(q);
  164. b.wrap(n);
  165. b.parent().append(c);
  166. b.parent().append(g);
  167. a.railDraggable && c.bind("mousedown", function(a) {
  168. var b = f(document);
  169. y = !0;
  170. t = parseFloat(c.css("top"));
  171. pageY = a.pageY;
  172. b.bind("mousemove.slimscroll", function(a) {
  173. currTop = t + a.pageY - pageY;
  174. c.css("top", currTop);
  175. m(0, c.position().top, !1)
  176. });
  177. b.bind("mouseup.slimscroll", function(a) {
  178. y = !1;
  179. p();
  180. b.unbind(".slimscroll")
  181. });
  182. return !1
  183. }).bind("selectstart.slimscroll", function(a) {
  184. a.stopPropagation();
  185. a.preventDefault();
  186. return !1
  187. });
  188. g.hover(function() {
  189. v()
  190. }, function() {
  191. p()
  192. });
  193. c.hover(function() {
  194. x = !0
  195. }, function() {
  196. x = !1
  197. });
  198. b.hover(function() {
  199. s = !0;
  200. v();
  201. p()
  202. }, function() {
  203. s = !1;
  204. p()
  205. });
  206. b.bind("touchstart", function(a, b) {
  207. a.originalEvent.touches.length && (z = a.originalEvent.touches[0].pageY)
  208. });
  209. b.bind("touchmove", function(b) {
  210. k || b.originalEvent.preventDefault();
  211. b.originalEvent.touches.length &&
  212. (m((z - b.originalEvent.touches[0].pageY) / a.touchScrollStep, !0), z = b.originalEvent.touches[0].pageY)
  213. });
  214. w();
  215. "bottom" === a.start ? (c.css({
  216. top: b.outerHeight() - c.outerHeight()
  217. }), m(0, !0)) : "top" !== a.start && (m(f(a.start).position().top, null, !0), a.alwaysVisible || c.hide());
  218. C()
  219. }
  220. });
  221. return this
  222. }
  223. });
  224. jQuery.fn.extend({
  225. slimscroll: jQuery.fn.slimScroll
  226. })
  227. })(jQuery);