Monday, July 30, 2012

jquery – javascript bind an event handler to horizontal scroll



Is there a way in javascript to bind an event handler to a horizontal scroll as opposed to the generic scroll event which is fired when the user scrolls horizontally and vertically? I want to trigger an event only when the user scrolls horizontally.


I searched around for an answer to this question, but couldn\’t seem to find anything.


Thanks!


P.S. My apologies if I\’m using some terminology incorrectly. I\’m fairly new to javascript.


UPDATE


Thanks so much for all your answers! In summary, it looks like you are all saying that this isn\’t supported in javascript, but I that I can accomplish the functionality with something like this (using jQuery) (jsFiddle):



var oldScrollTop = $(window).scrollTop();
var oldScrollLeft = $(window).scrollLeft();

$(window).scroll(function () {
if(oldScrollTop == $(window).scrollTop()) {
$(\'#current\').html(\'Horizontal\');
}
else {
$(\'#current\').html(\'Vertical\');
}
oldScrollTop = $(window).scrollTop();
oldScrollLeft = $(window).scrollLeft();
});​


That\’s all I needed to know. Thanks again!






Rating: 2 out of 5 based on 5 ratings



The post jquery – javascript bind an event handler to horizontal scroll appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-javascript-bind-an-event-handler-to-horizontal-scroll.html

No comments:

Post a Comment