简体   繁体   中英

Discover Mouse Position Relative to Restored Browser Window

How do I discover the mouse position relative to the viewable browser window? If you see screenshot below, I want to determine the co-ordinates of the mouse relative to the viewable area in the browser window whilst hovering over those four thumbnails. As you can see I consider the top left corner of the viewable area as 0, 0. I want the exact mouse position and not the position of the thumbnails and I want to achieve cross-browser compatibility.

在此处输入图片说明

Any help?

Found a solution:

$(document).ready(function () {
    $("img.thumbnails").mousemove(function (event) {
        //X relative to viewable area
        var X = (event.pageX - $(window).scrollLeft());

        //Y relative to viewable area
        var Y = (event.pageY - $(window).scrollTop());
    });
});

Thanks!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM