PostScrubber.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class='post_scrubber'>
  3. <div class='post_scrubber__line' ref='line' @click='lineClick'></div>
  4. <div
  5. class='post_scrubber__dragger'
  6. :style='{
  7. "top": draggerYCoordPx
  8. }'
  9. @mousedown.prevent.stop='setDragging(true)'
  10. @mouseup.prevent.stop='setDragging(false)'
  11. ></div>
  12. <div
  13. class='post_scrubber__dragger_info'
  14. :style='{
  15. "top": draggerYCoordPx
  16. }'
  17. >
  18. 012345
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'PostScrubber',
  25. data () {
  26. return {
  27. clientY: 0,
  28. lineTop: 0,
  29. lineHeight: 0,
  30. dragging: false,
  31. posts: 20
  32. }
  33. },
  34. computed: {
  35. draggerYCoordPx () {
  36. if(!this.clientY || !this.lineTop) return '0px'
  37. let top = this.clientY - this.lineTop
  38. if(top < 0) {
  39. return '0px'
  40. } else if(top > this.lineHeight) {
  41. return this.lineHeight + 'px'
  42. } else {
  43. return top + 'px'
  44. }
  45. }
  46. },
  47. methods: {
  48. setDragging (val) {
  49. this.dragging = val
  50. },
  51. lineClick (e) {
  52. this.clientY = e.clientY
  53. }
  54. },
  55. mounted () {
  56. let lineRect = this.$refs.line.getBoundingClientRect()
  57. this.lineTop = lineRect.top
  58. this.lineHeight = lineRect.height
  59. window.addEventListener('mousemove', e => {
  60. if(this.dragging) {
  61. this.clientY = e.clientY
  62. }
  63. })
  64. window.addEventListener('mouseup', e => {
  65. this.dragging = false
  66. })
  67. }
  68. }
  69. </script>
  70. <style lang='scss' scoped>
  71. @import '../assets/scss/variables.scss';
  72. .post_scrubber {
  73. height: 10rem;
  74. position: fixed;
  75. right: calc(10% + 5rem);
  76. margin-top: 5.25rem;
  77. @at-root #{&}__line {
  78. height: 100%;
  79. background-color: $color__gray--darker;
  80. border-radius: 1rem;
  81. width: 0.125rem;
  82. }
  83. @at-root #{&}__dragger {
  84. background-color: $color__blue--primary;
  85. width: 0.5rem;
  86. border-radius: 1rem;
  87. height: 1.5rem;
  88. position: absolute;
  89. top: 0;
  90. left: calc( (0.5rem - 0.125rem) / -2);
  91. margin-top: calc(-1.5rem / 2 );
  92. cursor: pointer;
  93. transition: background-color 0.2s;
  94. &:hover {
  95. background-color: $color__blue--darker;
  96. }
  97. &:active {
  98. background-color: $color__blue--darkest;
  99. }
  100. }
  101. @at-root #{&}__dragger_info {
  102. position: absolute;
  103. margin-top: calc(-1.5rem / 2 - 0.125rem);
  104. pointer-events: none;
  105. background-color: #fff;
  106. left: 1rem;
  107. font-size: 0.9rem;
  108. border-radius: 0.125rem;
  109. padding: 0.25rem;
  110. @extend .shadow_border;
  111. }
  112. }
  113. </style>