No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { TrackDirection } from './direction';
  2. import { setStyle } from '../utils/';
  3. var ScrollbarThumb = /** @class */ (function () {
  4. function ScrollbarThumb(_direction, _minSize) {
  5. if (_minSize === void 0) { _minSize = 0; }
  6. this._direction = _direction;
  7. this._minSize = _minSize;
  8. /**
  9. * Thumb element
  10. */
  11. this.element = document.createElement('div');
  12. /**
  13. * Display size of the thumb
  14. * will always be greater than `scrollbar.options.thumbMinSize`
  15. */
  16. this.displaySize = 0;
  17. /**
  18. * Actual size of the thumb
  19. */
  20. this.realSize = 0;
  21. /**
  22. * Thumb offset to the top
  23. */
  24. this.offset = 0;
  25. this.element.className = "scrollbar-thumb scrollbar-thumb-" + _direction;
  26. }
  27. /**
  28. * Attach to track element
  29. *
  30. * @param trackEl Track element
  31. */
  32. ScrollbarThumb.prototype.attachTo = function (trackEl) {
  33. trackEl.appendChild(this.element);
  34. };
  35. ScrollbarThumb.prototype.update = function (scrollOffset, containerSize, pageSize) {
  36. // calculate thumb size
  37. // pageSize > containerSize -> scrollable
  38. this.realSize = Math.min(containerSize / pageSize, 1) * containerSize;
  39. this.displaySize = Math.max(this.realSize, this._minSize);
  40. // calculate thumb offset
  41. this.offset = scrollOffset / pageSize * (containerSize + (this.realSize - this.displaySize));
  42. setStyle(this.element, this._getStyle());
  43. };
  44. ScrollbarThumb.prototype._getStyle = function () {
  45. switch (this._direction) {
  46. case TrackDirection.X:
  47. return {
  48. width: this.displaySize + "px",
  49. '-transform': "translate3d(" + this.offset + "px, 0, 0)",
  50. };
  51. case TrackDirection.Y:
  52. return {
  53. height: this.displaySize + "px",
  54. '-transform': "translate3d(0, " + this.offset + "px, 0)",
  55. };
  56. default:
  57. return null;
  58. }
  59. };
  60. return ScrollbarThumb;
  61. }());
  62. export { ScrollbarThumb };
  63. //# sourceMappingURL=thumb.js.map