scrollbar.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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 = 392);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 19:
  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/dom");
  75. /***/ }),
  76. /***/ 3:
  77. /***/ (function(module, exports) {
  78. module.exports = require("element-ui/lib/utils/util");
  79. /***/ }),
  80. /***/ 38:
  81. /***/ (function(module, exports) {
  82. module.exports = require("element-ui/lib/utils/scrollbar-width");
  83. /***/ }),
  84. /***/ 392:
  85. /***/ (function(module, exports, __webpack_require__) {
  86. module.exports = __webpack_require__(393);
  87. /***/ }),
  88. /***/ 393:
  89. /***/ (function(module, exports, __webpack_require__) {
  90. "use strict";
  91. exports.__esModule = true;
  92. var _main = __webpack_require__(394);
  93. var _main2 = _interopRequireDefault(_main);
  94. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  95. /* istanbul ignore next */
  96. _main2.default.install = function (Vue) {
  97. Vue.component(_main2.default.name, _main2.default);
  98. };
  99. exports.default = _main2.default;
  100. /***/ }),
  101. /***/ 394:
  102. /***/ (function(module, exports, __webpack_require__) {
  103. "use strict";
  104. exports.__esModule = true;
  105. var _resizeEvent = __webpack_require__(19);
  106. var _scrollbarWidth = __webpack_require__(38);
  107. var _scrollbarWidth2 = _interopRequireDefault(_scrollbarWidth);
  108. var _util = __webpack_require__(3);
  109. var _bar = __webpack_require__(395);
  110. var _bar2 = _interopRequireDefault(_bar);
  111. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  112. /* istanbul ignore next */
  113. // reference https://github.com/noeldelgado/gemini-scrollbar/blob/master/index.js
  114. exports.default = {
  115. name: 'ElScrollbar',
  116. components: { Bar: _bar2.default },
  117. props: {
  118. native: Boolean,
  119. wrapStyle: {},
  120. wrapClass: {},
  121. viewClass: {},
  122. viewStyle: {},
  123. noresize: Boolean, // 如果 container 尺寸不会发生变化,最好设置它可以优化性能
  124. tag: {
  125. type: String,
  126. default: 'div'
  127. }
  128. },
  129. data: function data() {
  130. return {
  131. sizeWidth: '0',
  132. sizeHeight: '0',
  133. moveX: 0,
  134. moveY: 0
  135. };
  136. },
  137. computed: {
  138. wrap: function wrap() {
  139. return this.$refs.wrap;
  140. }
  141. },
  142. render: function render(h) {
  143. var gutter = (0, _scrollbarWidth2.default)();
  144. var style = this.wrapStyle;
  145. if (gutter) {
  146. var gutterWith = '-' + gutter + 'px';
  147. var gutterStyle = 'margin-bottom: ' + gutterWith + '; margin-right: ' + gutterWith + ';';
  148. if (Array.isArray(this.wrapStyle)) {
  149. style = (0, _util.toObject)(this.wrapStyle);
  150. style.marginRight = style.marginBottom = gutterWith;
  151. } else if (typeof this.wrapStyle === 'string') {
  152. style += gutterStyle;
  153. } else {
  154. style = gutterStyle;
  155. }
  156. }
  157. var view = h(this.tag, {
  158. class: ['el-scrollbar__view', this.viewClass],
  159. style: this.viewStyle,
  160. ref: 'resize'
  161. }, this.$slots.default);
  162. var wrap = h(
  163. 'div',
  164. {
  165. ref: 'wrap',
  166. style: style,
  167. on: {
  168. 'scroll': this.handleScroll
  169. },
  170. 'class': [this.wrapClass, 'el-scrollbar__wrap', gutter ? '' : 'el-scrollbar__wrap--hidden-default'] },
  171. [[view]]
  172. );
  173. var nodes = void 0;
  174. if (!this.native) {
  175. nodes = [wrap, h(
  176. _bar2.default,
  177. {
  178. attrs: {
  179. move: this.moveX,
  180. size: this.sizeWidth }
  181. },
  182. []
  183. ), h(
  184. _bar2.default,
  185. {
  186. attrs: {
  187. vertical: true,
  188. move: this.moveY,
  189. size: this.sizeHeight }
  190. },
  191. []
  192. )];
  193. } else {
  194. nodes = [h(
  195. 'div',
  196. {
  197. ref: 'wrap',
  198. 'class': [this.wrapClass, 'el-scrollbar__wrap'],
  199. style: style },
  200. [[view]]
  201. )];
  202. }
  203. return h('div', { class: 'el-scrollbar' }, nodes);
  204. },
  205. methods: {
  206. handleScroll: function handleScroll() {
  207. var wrap = this.wrap;
  208. this.moveY = wrap.scrollTop * 100 / wrap.clientHeight;
  209. this.moveX = wrap.scrollLeft * 100 / wrap.clientWidth;
  210. },
  211. update: function update() {
  212. var heightPercentage = void 0,
  213. widthPercentage = void 0;
  214. var wrap = this.wrap;
  215. if (!wrap) return;
  216. heightPercentage = wrap.clientHeight * 100 / wrap.scrollHeight;
  217. widthPercentage = wrap.clientWidth * 100 / wrap.scrollWidth;
  218. this.sizeHeight = heightPercentage < 100 ? heightPercentage + '%' : '';
  219. this.sizeWidth = widthPercentage < 100 ? widthPercentage + '%' : '';
  220. }
  221. },
  222. mounted: function mounted() {
  223. if (this.native) return;
  224. this.$nextTick(this.update);
  225. !this.noresize && (0, _resizeEvent.addResizeListener)(this.$refs.resize, this.update);
  226. },
  227. beforeDestroy: function beforeDestroy() {
  228. if (this.native) return;
  229. !this.noresize && (0, _resizeEvent.removeResizeListener)(this.$refs.resize, this.update);
  230. }
  231. };
  232. /***/ }),
  233. /***/ 395:
  234. /***/ (function(module, exports, __webpack_require__) {
  235. "use strict";
  236. exports.__esModule = true;
  237. var _dom = __webpack_require__(2);
  238. var _util = __webpack_require__(396);
  239. /* istanbul ignore next */
  240. exports.default = {
  241. name: 'Bar',
  242. props: {
  243. vertical: Boolean,
  244. size: String,
  245. move: Number
  246. },
  247. computed: {
  248. bar: function bar() {
  249. return _util.BAR_MAP[this.vertical ? 'vertical' : 'horizontal'];
  250. },
  251. wrap: function wrap() {
  252. return this.$parent.wrap;
  253. }
  254. },
  255. render: function render(h) {
  256. var size = this.size,
  257. move = this.move,
  258. bar = this.bar;
  259. return h(
  260. 'div',
  261. {
  262. 'class': ['el-scrollbar__bar', 'is-' + bar.key],
  263. on: {
  264. 'mousedown': this.clickTrackHandler
  265. }
  266. },
  267. [h(
  268. 'div',
  269. {
  270. ref: 'thumb',
  271. 'class': 'el-scrollbar__thumb',
  272. on: {
  273. 'mousedown': this.clickThumbHandler
  274. },
  275. style: (0, _util.renderThumbStyle)({ size: size, move: move, bar: bar }) },
  276. []
  277. )]
  278. );
  279. },
  280. methods: {
  281. clickThumbHandler: function clickThumbHandler(e) {
  282. this.startDrag(e);
  283. this[this.bar.axis] = e.currentTarget[this.bar.offset] - (e[this.bar.client] - e.currentTarget.getBoundingClientRect()[this.bar.direction]);
  284. },
  285. clickTrackHandler: function clickTrackHandler(e) {
  286. var offset = Math.abs(e.target.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]);
  287. var thumbHalf = this.$refs.thumb[this.bar.offset] / 2;
  288. var thumbPositionPercentage = (offset - thumbHalf) * 100 / this.$el[this.bar.offset];
  289. this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
  290. },
  291. startDrag: function startDrag(e) {
  292. e.stopImmediatePropagation();
  293. this.cursorDown = true;
  294. (0, _dom.on)(document, 'mousemove', this.mouseMoveDocumentHandler);
  295. (0, _dom.on)(document, 'mouseup', this.mouseUpDocumentHandler);
  296. document.onselectstart = function () {
  297. return false;
  298. };
  299. },
  300. mouseMoveDocumentHandler: function mouseMoveDocumentHandler(e) {
  301. if (this.cursorDown === false) return;
  302. var prevPage = this[this.bar.axis];
  303. if (!prevPage) return;
  304. var offset = (this.$el.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]) * -1;
  305. var thumbClickPosition = this.$refs.thumb[this.bar.offset] - prevPage;
  306. var thumbPositionPercentage = (offset - thumbClickPosition) * 100 / this.$el[this.bar.offset];
  307. this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
  308. },
  309. mouseUpDocumentHandler: function mouseUpDocumentHandler(e) {
  310. this.cursorDown = false;
  311. this[this.bar.axis] = 0;
  312. (0, _dom.off)(document, 'mousemove', this.mouseMoveDocumentHandler);
  313. document.onselectstart = null;
  314. }
  315. },
  316. destroyed: function destroyed() {
  317. (0, _dom.off)(document, 'mouseup', this.mouseUpDocumentHandler);
  318. }
  319. };
  320. /***/ }),
  321. /***/ 396:
  322. /***/ (function(module, exports, __webpack_require__) {
  323. "use strict";
  324. exports.__esModule = true;
  325. exports.renderThumbStyle = renderThumbStyle;
  326. var BAR_MAP = exports.BAR_MAP = {
  327. vertical: {
  328. offset: 'offsetHeight',
  329. scroll: 'scrollTop',
  330. scrollSize: 'scrollHeight',
  331. size: 'height',
  332. key: 'vertical',
  333. axis: 'Y',
  334. client: 'clientY',
  335. direction: 'top'
  336. },
  337. horizontal: {
  338. offset: 'offsetWidth',
  339. scroll: 'scrollLeft',
  340. scrollSize: 'scrollWidth',
  341. size: 'width',
  342. key: 'horizontal',
  343. axis: 'X',
  344. client: 'clientX',
  345. direction: 'left'
  346. }
  347. };
  348. function renderThumbStyle(_ref) {
  349. var move = _ref.move,
  350. size = _ref.size,
  351. bar = _ref.bar;
  352. var style = {};
  353. var translate = 'translate' + bar.axis + '(' + move + '%)';
  354. style[bar.size] = size;
  355. style.transform = translate;
  356. style.msTransform = translate;
  357. style.webkitTransform = translate;
  358. return style;
  359. };
  360. /***/ })
  361. /******/ });