最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Want horizontal scroll in mouse wheel scrolling Nuxt js - Stack Overflow

programmeradmin0浏览0评论

Here is my simple HTML markup style. So, when I am using the mouse wheel I want to scroll the content horizontally. `

<div class="col-md-9" style="max-height: 80vh;overflow-y: hidden" id="scroll_container">
  <div class="container-fluid" >
                <div class="row flex-row flex-nowrap">
                  <div class="col-md-4">
                    Card 1
                  </div>
                  <div class="col-md-4 mb-4" >
                    Card 2
                  </div>
                  <div class="col-md-4">
                    Card 3
                  </div>
                  <div class="col-md-4">
                    Card 4
                  </div>
                </div>
              </div>
</div>

`

Here is my simple HTML markup style. So, when I am using the mouse wheel I want to scroll the content horizontally. `

<div class="col-md-9" style="max-height: 80vh;overflow-y: hidden" id="scroll_container">
  <div class="container-fluid" >
                <div class="row flex-row flex-nowrap">
                  <div class="col-md-4">
                    Card 1
                  </div>
                  <div class="col-md-4 mb-4" >
                    Card 2
                  </div>
                  <div class="col-md-4">
                    Card 3
                  </div>
                  <div class="col-md-4">
                    Card 4
                  </div>
                </div>
              </div>
</div>

`

Share Improve this question asked Nov 8, 2020 at 8:48 Md. Morshadun NurMd. Morshadun Nur 1451 silver badge9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Here's what I did to make it little more "Vue". I set a ref on the HTML element I want to scroll as well as a @mousewheel event. Then in the triggered method, I reference the element by $ref and pretty much do what OP did with the .scrollLeft += e.deltaY.

Here's what it looks like:

<div ref="scroll_container" @mousewheel="scrollX">
  ...
</div>

...

methods: {
  scrollX(e) {
    this.$refs['scroll_container'].scrollLeft += e.deltaY;
  },
},

I need to add an event listener in vue created life cycle.

document.addEventListener('wheel', (e) => {
      document.getElementById('scroll_container').scrollLeft += e.deltaY;
    })
发布评论

评论列表(0)

  1. 暂无评论