当前位置:   article > 正文

vue el-tabs 鼠标滚轮滚动切换_vue tabs鼠标移上滑动

vue tabs鼠标移上滑动

把el-tabs  el-tab-pane的name拿来做一个数组

activeName: 'first',

arrtab: ['first', 'third', 'fourth', 'second', 'dongtai', 'dianping', 'xiangce'],

  1. //鼠标滚动事件
  2. handleScroll(e) {
  3. console.log("arrtab",this.arrtab.length)
  4. //let name = this.activeName;
  5. let direction = e.deltaY > 0 ? 'down' : 'up'; //deltaY为正则滚轮向下,为负滚轮向上
  6. if (direction == 'down' && e.deltaY >= 100) {
  7. let index = this.arrtab.indexOf(this.activeName);
  8. if (index < this.arrtab.length-1) {
  9. index++;
  10. console.log(index)
  11. this.activeName = this.arrtab[index]
  12. }
  13. console.log("下");
  14. }
  15. if (direction == 'up' && e.deltaY <= -100) {
  16. let index = this.arrtab.indexOf(this.activeName);
  17. if (index >= 1) {
  18. index--;
  19. console.log(index)
  20. this.activeName = this.arrtab[index]
  21. }
  22. console.log("上");
  23. }
  24. console.log(this.activeName);
  25. },
  26. debounce(func, wait = 100, immediate = true)
  27. {
  28. let timer
  29. return (...args) => {
  30. let context = this
  31. if (timer) clearTimeout(timer)
  32. if (immediate) {
  33. let callNow = !timer
  34. timer = setTimeout(() => {
  35. timer = null
  36. }, wait)
  37. if (callNow) func.apply(context, args)
  38. } else {
  39. timer = setTimeout(() => {
  40. func.apply(context, args)
  41. }, wait)
  42. }
  43. }
  44. }

  1. mounted() {
  2. //监听鼠标滚动事件
  3. window.addEventListener('mousewheel', this.debounce(this.handleScroll),false);
  4. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/383573
推荐阅读