Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Util.getPosition() fix for mouse pointer offset when page is scrolled down #295

Closed
wants to merge 1 commit into from

Conversation

erikgull
Copy link

This commit partly fixes #258 for the case when the canvas is not scaled.

All credits to Brian Huisman, the author of http://www.greywyvern.com/?post=331 .

@kanaka
Copy link
Member

kanaka commented Aug 30, 2013

WIth a quick search I was not able to determine the license of this code. Please update if you can provide information on the license. Thanks.

@erikgull
Copy link
Author

I contacted Brian Huisman, and he states the following in the e-mail reply: "Unless otherwise noted, code on my site is public domain. You may credit me if you like, but it's not necessary.".

@emmar
Copy link

emmar commented Dec 16, 2013

This fix also needs to be applied to scrollLeft. You don't have to include my code as your fix, but this is how I changed erikgull's scrollDist function to make the mouse position correct when you scroll either horizontally or vertically.

function scrollDist() 
        {
        var myScrollTop, myScrollLeft;
        var html = document.getElementsByTagName('html')[0];

        // get the scrollTop part
        if (html.scrollTop && document.documentElement.scrollTop) 
            {myScrollTop = html.scrollTop;} 
        else if (html.scrollTop || document.documentElement.scrollTop) 
            {myScrollTop = html.scrollTop + document.documentElement.scrollTop;} 
        else if (document.body.scrollTop) 
            {myScrollTop = document.body.scrollTop;}
        else {myScrollTop = 0;}

        // get the scrollLeft part
        if (html.scrollLeft && document.documentElement.scrollLeft) 
            {myScrollLeft = html.scrollLeft;} 
        else if (html.scrollLeft || document.documentElement.scrollLeft) 
            {myScrollLeft = html.scrollLeft + document.documentElement.scrollLeft;} 
        else if (document.body.scrollLeft) 
            {myScrollLeft = document.body.scrollLeft;}
        else {myScrollLeft = 0;}

        return [myScrollLeft, myScrollTop];
        };

@denouche
Copy link

Will this patch be merged ?
I really need it !
Thank you for your help.

@samhed
Copy link
Member

samhed commented Jan 11, 2014

The problem which @emmar mentioned would need to be included as well. @erikgull can you fix this?

@DirectXMan12
Copy link
Member

I'm going to go ahead an fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

position: fixed css does not register mouse position correctly
6 participants