scrollbar.js 11 KB

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