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

How to trigger javascript mouse scroll wheel on a divs horizontal scrollbar? - Stack Overflow

programmeradmin1浏览0评论

I have a div with a nested div that are larger. The overflow-x is set to auto, such a scroll bare appears. I would like to make such that if the user scrolls(with the mouse wheel) within the div, the scrollbar scrolls horizontal.

<div id="outer" style="width:1000px;overflow-x:auto">
      <div id="inner" style="width:2000px"></div>
</div>

What kind of javascript is needed for this. Remember that the scrollbar es automatic, not looking for a solution with javascript changing left/right positions.

I have a div with a nested div that are larger. The overflow-x is set to auto, such a scroll bare appears. I would like to make such that if the user scrolls(with the mouse wheel) within the div, the scrollbar scrolls horizontal.

<div id="outer" style="width:1000px;overflow-x:auto">
      <div id="inner" style="width:2000px"></div>
</div>

What kind of javascript is needed for this. Remember that the scrollbar es automatic, not looking for a solution with javascript changing left/right positions.

Share Improve this question asked Oct 16, 2012 at 13:54 Poul K. SørensenPoul K. Sørensen 17.6k24 gold badges139 silver badges294 bronze badges 1
  • possible duplicate of How to do a horizontal scroll on mouse wheel scroll? – Dave Swersky Commented Oct 16, 2012 at 13:57
Add a ment  | 

1 Answer 1

Reset to default 6

Why changing scrollLeft doesn't fit you?

document.getElementById('outer').addEventListener('mousewheel', function(e) {
  this.scrollLeft -= (e.wheelDelta);
  e.preventDefault();
}, false);
发布评论

评论列表(0)

  1. 暂无评论