how to scroll one block through another

Viewed 33

I have a slider on my page with an absolutely positioned block on top of it. How can I make the slider scroll the same distance as the mouse traveled on mousedown and mousemove events?

$(document).mouseup(function(e) {
  drag = false;
  left = scrollContainer.scrollLeft;

  $(".scroll_control").mousedown(function(e) {
    drag = true;
    coorX = e.pageX - scrollContainer.offsetLeft;
  });

  $(".scroll_control").mousemove(function(e) {
    if (drag) {
      scrollContainer.scrollLeft -= (e.pageX - coorX) * speed;
    }
  });
});

0 Answers
Related