Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141367

Vertical scroll with mouse movement inside a div

$
0
0

I'm using drupal and I cannot change the html. The problem is that all the other articles said to include a container, and I cannot do that. How do I vertical scroll with mouse movement? Example: https://test-ca3969.webflow.io/ (see the OUR LOCATIONS section).

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

Is there a way to do something like the following code, but replace "window" with something like "$('.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;

Viewing all articles
Browse latest Browse all 141367

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>