Zoom page -> Mouse position wrong?

D

DJ WIce

Hi,

I have a function on my page to zoom in (for people who have not very good
eyes for example):

var zoom_factor=100;
function zoom(how)
{
var bodyStyle = document.body.style;
zoom_factor = (how)?100:110;
zoomed = bodyStyle.zoom;
if ((zoomed)&&(zoom_factor!=100))
zoom_factor=parseInt(zoomed)*parseInt(zoom_factor)/100;
bodyStyle.setAttribute('zoom', parseInt(zoom_factor)+'%');
}


I also have a function to locate the mouse cursor:

var x, y;
function TraceMouse(e)
{
x = (document.all) ? document.body.scrollLeft + event.clientX : e.pageX;
y = (document.all) ? document.body.scrollTop + event.clientY : e.pageY;
flag = 1;
}
if (!document.all)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = TraceMouse;


Now I want to write some menu on the place where the mouse is oncontextmenu.
But when the page is zoomed in, the menu is placed more down than usual.

The page (just a page I make to test what is possible with javascript):
http://www.djwice.com/contextmenu.html
The script:
http://www.djwice.com/contextmenu/contextmenu.js

If anyone has ideas why it goes wrong, please let me know.
Thanks,
Wouter
 
D

DJ WIce

Problem solved:

If one zooms the mouse position is the location on the not zoomed page.
But the placement pixels are the position on the new page.
So one need to correct for the zoom_factor.

Wouter

: Hi,
:
: I have a function on my page to zoom in (for people who have not very good
: eyes for example):
:
: var zoom_factor=100;
: function zoom(how)
: {
: var bodyStyle = document.body.style;
: zoom_factor = (how)?100:110;
: zoomed = bodyStyle.zoom;
: if ((zoomed)&&(zoom_factor!=100))
: zoom_factor=parseInt(zoomed)*parseInt(zoom_factor)/100;
: bodyStyle.setAttribute('zoom', parseInt(zoom_factor)+'%');
: }
:
:
: I also have a function to locate the mouse cursor:
:
: var x, y;
: function TraceMouse(e)
: {
: x = (document.all) ? document.body.scrollLeft + event.clientX : e.pageX;
: y = (document.all) ? document.body.scrollTop + event.clientY : e.pageY;
: flag = 1;
: }
: if (!document.all)
: document.captureEvents(Event.MOUSEMOVE);
: document.onmousemove = TraceMouse;
:
:
: Now I want to write some menu on the place where the mouse is
oncontextmenu.
: But when the page is zoomed in, the menu is placed more down than usual.
:
: The page (just a page I make to test what is possible with javascript):
: http://www.djwice.com/contextmenu.html
: The script:
: http://www.djwice.com/contextmenu/contextmenu.js
:
: If anyone has ideas why it goes wrong, please let me know.
: Thanks,
: Wouter
:
:
:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top