javascript - How do I detect "Mouse wheel scroll" and "Window manual scroll" both differently in Jquery -
i working on 1 project want action when user use mouse wheel scroll , window scroll (by scrolling scroll bar on right side)
have come on solution action in both manners i.e. when user scroll mouse wheel , manually using scroll bar on window.
here code detect mouse wheel , window scroll bar
$(window).scroll(function(event){ var st = $(this).scrolltop(); if (st > lastscrolltop){ $( "#gear1" ).css( "-webkit-transform", "rotate(" + (r + 10) + "deg)" ); r = r + 10; } else { $( "#gear1" ).css( "-webkit-transform", "rotate(" + (r - 10) + "deg)" ); r = r - 10; } lastscroll = st; });
want diffrent action when user scroll through mouse wheel , user scroll through window scroll bar.
need this:
if (scroll type mouse wheel ){ // action } if (scroll type window scroll (scrolling scrollbar on right side of browser window) ){ // action }
you use library detect mousewheel movements. here's how use jquery(code copied docs) :
$('#my_elem').on('mousewheel', function(event) { //... });
or, use following code without using library, :
$('body,html').bind('scroll mousedown wheel dommousescroll mousewheel keyup', function(e){ if ( e.which > 0 || e.type == "mousedown" || e.type == "mousewheel"){ //... } })
and if use second option, code detect scroll without mousewheel :
$(window).scroll(function(e){ //... });
Comments
Post a Comment