Skip to content Skip to sidebar Skip to footer

Pagey On Div With Overflow-y

I am using a script that detects where your mouse enters on hover. I'm trying to use the script within a div with overflow-y: scroll The script uses pageY which detects position r

Solution 1:

I'm not exactly sure what you are trying to do on your jsfiddle example as you didn't explain that. But just to answer your question, you just need to subtract the mouse position (pageX & pageY) to the containing <div>'s offset() position then add the <div> scroll position (scrollTop() & scrollLeft()).

$('div').mousemove(function (e) {
    var offset = $(this).offset();
    var x = e.pageX - offset.left + $(this).scrollLeft();
    var y = e.pageY - offset.top + $(this).scrollTop();
});

Check this jsfiddle.

Post a Comment for "Pagey On Div With Overflow-y"