Javascript Help
I have a javascript that pops up an image box when i hover over a link, it aligns the box 20 pixels to the right of the mousepointer using the code below
var offX= 20; // how far from mouse to show tip
Can anyone tell me how to just centre the popup box on the screen rather than position it in relation to the mouse pointer??
Thanks
Andy
[Edited by Avi - 11/14/2003 2:33:29 PM]
var offX= 20; // how far from mouse to show tip
Can anyone tell me how to just centre the popup box on the screen rather than position it in relation to the mouse pointer??
Thanks
Andy
[Edited by Avi - 11/14/2003 2:33:29 PM]
I use this code for opening a new window
var width = winw + 40;
var height = winh + 60;
var left = (screen.availWidth - width) / 2;
var top = (screen.availHeight - height) / 2;
then add the following to your window.open :- top="+top+",left="+left+",width="+width+",height=" +height
where 'winw' is the width and 'winh' is the height of a picture going into the window.
if every window is going to be the same size you can change the var width and var height to the actual figures.
Stuart
[Edited by sasim - 11/14/2003 3:01:40 PM]
var width = winw + 40;
var height = winh + 60;
var left = (screen.availWidth - width) / 2;
var top = (screen.availHeight - height) / 2;
then add the following to your window.open :- top="+top+",left="+left+",width="+width+",height=" +height
where 'winw' is the width and 'winh' is the height of a picture going into the window.
if every window is going to be the same size you can change the var width and var height to the actual figures.
Stuart
[Edited by sasim - 11/14/2003 3:01:40 PM]
Not sure how to do that Stuart, says winw is undefined when i try, i'm no expert at javascipt( actually i;m clueless
) here's a link to the page, to try and help explain,
http://www.aviz.co.uk/cit/stafftest.htm
I'm trying to make the pop up box be in the centre of the page all the time, rather than relative to where the mouse is.
Any help appreciated
) here's a link to the page, to try and help explain,http://www.aviz.co.uk/cit/stafftest.htm
I'm trying to make the pop up box be in the centre of the page all the time, rather than relative to where the mouse is.
Any help appreciated
<body>
<script language="JavaScript">
// document.write("Screen Resolution: ");
// document.write(screen.width," x ",screen.height);
var popurl="file.htm";
var screen_height = screen.height;
var screen_width = screen.width;
var window_height = 121;
var window_width = 256;
var offset_x = ((screen_width - window_width) / 2);
var offset_y = ((screen_height - window_height) / 2);
winpops = window.open(popurl,"","width=" + window_width + ",height=" + window_height + ",left=" + offset_x + ",top=" + offset_y);
</script>
</body>
<script language="JavaScript">
// document.write("Screen Resolution: ");
// document.write(screen.width," x ",screen.height);
var popurl="file.htm";
var screen_height = screen.height;
var screen_width = screen.width;
var window_height = 121;
var window_width = 256;
var offset_x = ((screen_width - window_width) / 2);
var offset_y = ((screen_height - window_height) / 2);
winpops = window.open(popurl,"","width=" + window_width + ",height=" + window_height + ",left=" + offset_x + ",top=" + offset_y);
</script>
</body>
SJ - I'm not trying to create a pop up window, if you have a look at the link, i just need to get the java pop up box to position itself centrally rather than in position to the mouse.
Cheers
Andy
Cheers
Andy
just below:
if ((mouseX+offX+tpWd)>winWd)
tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
put
tipcss.left = 100;
and if you want to fix the top height then just below:
if ((mouseY+offY+tpHt)>winHt)
tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
put
tipcss.top = 200;
This will basically override any values set by the two if's and set the position to what you've specified. Minimal effort, you can comment out the two defunct lines using // if you want.
If you want to center it play with window.innerWidth and window.innerHeight on the lines you've added above.
HTH
~Jules
if ((mouseX+offX+tpWd)>winWd)
tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
put
tipcss.left = 100;
and if you want to fix the top height then just below:
if ((mouseY+offY+tpHt)>winHt)
tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
put
tipcss.top = 200;
This will basically override any values set by the two if's and set the position to what you've specified. Minimal effort, you can comment out the two defunct lines using // if you want.
If you want to center it play with window.innerWidth and window.innerHeight on the lines you've added above.
HTH
~Jules
Thread
Thread Starter
Forum
Replies
Last Post
CodeKey@Lisan
Computer & Technology Related
11
Feb 20, 2004 05:23 PM
RichB
Computer & Technology Related
2
Nov 5, 2003 02:27 PM



