在div内通过鼠标移动进行垂直滚动

时间:2019-12-16 17:44:10

标签: javascript jquery scroll mousemove

我正在使用drupal,但是我无法更改html。问题在于所有其他文章都说要包含一个容器,而我不能这样做。 如何通过鼠标移动垂直滚动?示例:https://test-ca3969.webflow.io/(请参见“我们的位置”部分)。

HTML:

<div class="view-content"
    <div class="topic"></div>
    <div class="topic"></div>
    <div class="topic"></div>
    ...
<div/>

CSS:

.view-content{
    overflow-y: scroll;
    overflow-x: hidden;
    height: 500px;
}

是否可以执行类似以下代码的方式,但是将“ window”替换为“ $('。view-content')”之类的内容?

JS:

            // Variables for current position
            var y;

            function handleMouse(e) {
              // Verify that x and y already have some value
              if (y) {
                // Scroll window by difference between current and previous positions
                window.scrollBy(0, e.clientY - y);
              }

              // Store current position
              y = e.clientY;
            }

            // Assign handleMouse to mouse movement events
            document.onmousemove = handleMouse;

0 个答案:

没有答案
相关问题