How to scroll within an element, controlled by a mouse click?

  • 0
    Good afternoon.
    I have a code that allows me to scroll inside my browser window by holding down the mouse button and moving it, it works pretty well.
    Question: how to do the same, but inside a separate div with overflow: scroll style?

    Here is my code at the moment:

    $(function(){
      var curDown = false,
          curYPos = 0,
          curXPos = 0;
      
      $(window).mousemove(function(m){
        if(curDown){
          window.scrollBy(curXPos - m.pageX, curYPos - m.pageY)
        }
      });
      
      $(window).mousedown(function(m){
        curYPos = m.pageY;
        curXPos = m.pageX;
        curDown = true;
      });
      
      $(window).mouseup(function(){
        curDown = false;
      });
    })
    JavaScript Anonymous, Dec 7, 2019

  • 1 Answers
  • 0
    For example use native scrolling. And in general, why implement such a thing when (judging by the code) this behavior has already been implemented through the mouse wheel?
    Reese Hampton

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!