Determine whether user clicking scrollbar or content (onclick for native scroll bar)

Solved:

A shortest scrollbar click detection I could come up with, tested on IE, Firefox, Chrome.

var clickedOnScrollbar = function(mouseX){
  if( $(window).outerWidth() <= mouseX ){
    return true;
  }
}

$(document).mousedown(function(e){
  if( clickedOnScrollbar(e.clientX) ){
    alert("clicked on scrollbar");
  }
});

Working example:
https://jsfiddle.net/s6mho19z/

Leave a Comment