I have a event bind to mousewheel in which I use the event to make some calculations, I would like to be able to use the same function to perform the same calculations from touch devices.
my code is like:
$('#element').bind("mousewheel DOMMouseScroll", function(event) {
event.preventDefault();
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0)
//do stuff
else {
//do other stuff
}
});
EDIT: As from the comment I understand i was not completely clear, my goal is to obtain a value like " wheelDelta " that make me recognize if the user is scrolling (touchmoving) up or down
This may not be the appropriate solution but you may do something like this.
var lastScroll = 0;
$('#element').on("scroll", function() {
var st = $(this).scrollTop();
if (st > lastScroll){
// downscroll code
//$(this).trigger("mousewheeldown");
} else {
// upscroll code
//$(this).trigger("mousewheelup");
}
lastScroll = st;
$(this).trigger("mousewheel");
});
I hope that helps :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.