scrollbar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(254);
  37. /***/ },
  38. /***/ 47:
  39. /***/ function(module, exports) {
  40. module.exports = require("element-ui/lib/utils/resize-event");
  41. /***/ },
  42. /***/ 117:
  43. /***/ function(module, exports) {
  44. module.exports = require("element-ui/lib/utils/dom");
  45. /***/ },
  46. /***/ 254:
  47. /***/ function(module, exports, __webpack_require__) {
  48. 'use strict';
  49. exports.__esModule = true;
  50. var _main = __webpack_require__(255);
  51. var _main2 = _interopRequireDefault(_main);
  52. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  53. /* istanbul ignore next */
  54. _main2.default.install = function (Vue) {
  55. Vue.component(_main2.default.name, _main2.default);
  56. };
  57. exports.default = _main2.default;
  58. /***/ },
  59. /***/ 255:
  60. /***/ function(module, exports, __webpack_require__) {
  61. 'use strict';
  62. exports.__esModule = true;
  63. var _resizeEvent = __webpack_require__(47);
  64. var _scrollbarWidth = __webpack_require__(256);
  65. var _scrollbarWidth2 = _interopRequireDefault(_scrollbarWidth);
  66. var _util = __webpack_require__(257);
  67. var _bar = __webpack_require__(258);
  68. var _bar2 = _interopRequireDefault(_bar);
  69. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  70. /* istanbul ignore next */
  71. // reference https://github.com/noeldelgado/gemini-scrollbar/blob/master/index.js
  72. exports.default = {
  73. name: 'ElScrollbar',
  74. components: { Bar: _bar2.default },
  75. props: {
  76. native: Boolean,
  77. wrapStyle: {},
  78. wrapClass: {},
  79. viewClass: {},
  80. viewStyle: {},
  81. noresize: Boolean, // 如果 container 尺寸不会发生变化,最好设置它可以优化性能
  82. tag: {
  83. type: String,
  84. default: 'div'
  85. }
  86. },
  87. data: function data() {
  88. return {
  89. sizeWidth: '0',
  90. sizeHeight: '0',
  91. moveX: 0,
  92. moveY: 0
  93. };
  94. },
  95. computed: {
  96. wrap: function wrap() {
  97. return this.$refs.wrap;
  98. }
  99. },
  100. render: function render(h) {
  101. var gutter = (0, _scrollbarWidth2.default)();
  102. var style = this.wrapStyle;
  103. if (gutter) {
  104. var gutterWith = '-' + gutter + 'px';
  105. var gutterStyle = 'margin-bottom: ' + gutterWith + '; margin-right: ' + gutterWith + ';';
  106. if (Array.isArray(this.wrapStyle)) {
  107. style = (0, _util.toObject)(this.wrapStyle);
  108. style.marginRight = style.marginBottom = gutterWith;
  109. } else if (typeof this.wrapStyle === 'string') {
  110. style += gutterStyle;
  111. } else {
  112. style = gutterStyle;
  113. }
  114. }
  115. var view = h(this.tag, {
  116. class: ['el-scrollbar__view', this.viewClass],
  117. style: this.viewStyle,
  118. ref: 'resize'
  119. }, this.$slots.default);
  120. var wrap = h(
  121. 'div',
  122. {
  123. ref: 'wrap',
  124. style: style,
  125. on: {
  126. 'scroll': this.handleScroll
  127. },
  128. 'class': [this.wrapClass, 'el-scrollbar__wrap', gutter ? '' : 'el-scrollbar__wrap--hidden-default'] },
  129. [[view]]
  130. );
  131. var nodes = void 0;
  132. if (!this.native) {
  133. nodes = [wrap, h(
  134. _bar2.default,
  135. {
  136. attrs: {
  137. move: this.moveX,
  138. size: this.sizeWidth }
  139. },
  140. []
  141. ), h(
  142. _bar2.default,
  143. {
  144. attrs: {
  145. vertical: true,
  146. move: this.moveY,
  147. size: this.sizeHeight }
  148. },
  149. []
  150. )];
  151. } else {
  152. nodes = [h(
  153. 'div',
  154. {
  155. ref: 'wrap',
  156. 'class': [this.wrapClass, 'el-scrollbar__wrap'],
  157. style: style },
  158. [[view]]
  159. )];
  160. }
  161. return h('div', { class: 'el-scrollbar' }, nodes);
  162. },
  163. methods: {
  164. handleScroll: function handleScroll() {
  165. var wrap = this.wrap;
  166. this.moveY = wrap.scrollTop * 100 / wrap.clientHeight;
  167. this.moveX = wrap.scrollLeft * 100 / wrap.clientWidth;
  168. },
  169. update: function update() {
  170. var heightPercentage = void 0,
  171. widthPercentage = void 0;
  172. var wrap = this.wrap;
  173. if (!wrap) return;
  174. heightPercentage = wrap.clientHeight * 100 / wrap.scrollHeight;
  175. widthPercentage = wrap.clientWidth * 100 / wrap.scrollWidth;
  176. this.sizeHeight = heightPercentage < 100 ? heightPercentage + '%' : '';
  177. this.sizeWidth = widthPercentage < 100 ? widthPercentage + '%' : '';
  178. }
  179. },
  180. mounted: function mounted() {
  181. if (this.native) return;
  182. this.$nextTick(this.update);
  183. !this.noresize && (0, _resizeEvent.addResizeListener)(this.$refs.resize, this.update);
  184. },
  185. beforeDestroy: function beforeDestroy() {
  186. if (this.native) return;
  187. !this.noresize && (0, _resizeEvent.removeResizeListener)(this.$refs.resize, this.update);
  188. }
  189. };
  190. /***/ },
  191. /***/ 256:
  192. /***/ function(module, exports) {
  193. module.exports = require("element-ui/lib/utils/scrollbar-width");
  194. /***/ },
  195. /***/ 257:
  196. /***/ function(module, exports) {
  197. module.exports = require("element-ui/lib/utils/util");
  198. /***/ },
  199. /***/ 258:
  200. /***/ function(module, exports, __webpack_require__) {
  201. 'use strict';
  202. exports.__esModule = true;
  203. var _dom = __webpack_require__(117);
  204. var _util = __webpack_require__(259);
  205. /* istanbul ignore next */
  206. exports.default = {
  207. name: 'Bar',
  208. props: {
  209. vertical: Boolean,
  210. size: String,
  211. move: Number
  212. },
  213. computed: {
  214. bar: function bar() {
  215. return _util.BAR_MAP[this.vertical ? 'vertical' : 'horizontal'];
  216. },
  217. wrap: function wrap() {
  218. return this.$parent.wrap;
  219. }
  220. },
  221. render: function render(h) {
  222. var size = this.size,
  223. move = this.move,
  224. bar = this.bar;
  225. return h(
  226. 'div',
  227. {
  228. 'class': ['el-scrollbar__bar', 'is-' + bar.key],
  229. on: {
  230. 'mousedown': this.clickTrackHandler
  231. }
  232. },
  233. [h(
  234. 'div',
  235. {
  236. ref: 'thumb',
  237. 'class': 'el-scrollbar__thumb',
  238. on: {
  239. 'mousedown': this.clickThumbHandler
  240. },
  241. style: (0, _util.renderThumbStyle)({ size: size, move: move, bar: bar }) },
  242. []
  243. )]
  244. );
  245. },
  246. methods: {
  247. clickThumbHandler: function clickThumbHandler(e) {
  248. this.startDrag(e);
  249. this[this.bar.axis] = e.currentTarget[this.bar.offset] - (e[this.bar.client] - e.currentTarget.getBoundingClientRect()[this.bar.direction]);
  250. },
  251. clickTrackHandler: function clickTrackHandler(e) {
  252. var offset = Math.abs(e.target.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]);
  253. var thumbHalf = this.$refs.thumb[this.bar.offset] / 2;
  254. var thumbPositionPercentage = (offset - thumbHalf) * 100 / this.$el[this.bar.offset];
  255. this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
  256. },
  257. startDrag: function startDrag(e) {
  258. e.stopImmediatePropagation();
  259. this.cursorDown = true;
  260. (0, _dom.on)(document, 'mousemove', this.mouseMoveDocumentHandler);
  261. (0, _dom.on)(document, 'mouseup', this.mouseUpDocumentHandler);
  262. document.onselectstart = function () {
  263. return false;
  264. };
  265. },
  266. mouseMoveDocumentHandler: function mouseMoveDocumentHandler(e) {
  267. if (this.cursorDown === false) return;
  268. var prevPage = this[this.bar.axis];
  269. if (!prevPage) return;
  270. var offset = (this.$el.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]) * -1;
  271. var thumbClickPosition = this.$refs.thumb[this.bar.offset] - prevPage;
  272. var thumbPositionPercentage = (offset - thumbClickPosition) * 100 / this.$el[this.bar.offset];
  273. this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
  274. },
  275. mouseUpDocumentHandler: function mouseUpDocumentHandler(e) {
  276. this.cursorDown = false;
  277. this[this.bar.axis] = 0;
  278. (0, _dom.off)(document, 'mousemove', this.mouseMoveDocumentHandler);
  279. document.onselectstart = null;
  280. }
  281. },
  282. destroyed: function destroyed() {
  283. (0, _dom.off)(document, 'mouseup', this.mouseUpDocumentHandler);
  284. }
  285. };
  286. /***/ },
  287. /***/ 259:
  288. /***/ function(module, exports) {
  289. 'use strict';
  290. exports.__esModule = true;
  291. exports.renderThumbStyle = renderThumbStyle;
  292. var BAR_MAP = exports.BAR_MAP = {
  293. vertical: {
  294. offset: 'offsetHeight',
  295. scroll: 'scrollTop',
  296. scrollSize: 'scrollHeight',
  297. size: 'height',
  298. key: 'vertical',
  299. axis: 'Y',
  300. client: 'clientY',
  301. direction: 'top'
  302. },
  303. horizontal: {
  304. offset: 'offsetWidth',
  305. scroll: 'scrollLeft',
  306. scrollSize: 'scrollWidth',
  307. size: 'width',
  308. key: 'horizontal',
  309. axis: 'X',
  310. client: 'clientX',
  311. direction: 'left'
  312. }
  313. };
  314. function renderThumbStyle(_ref) {
  315. var move = _ref.move,
  316. size = _ref.size,
  317. bar = _ref.bar;
  318. var style = {};
  319. var translate = 'translate' + bar.axis + '(' + move + '%)';
  320. style[bar.size] = size;
  321. style.transform = translate;
  322. style.msTransform = translate;
  323. style.webkitTransform = translate;
  324. return style;
  325. };
  326. /***/ }
  327. /******/ });