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

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

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;
    })

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745141697a4613459.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信