Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Javascript Help

Thread Tools
 
Search this Thread
 
Old Nov 14, 2003 | 02:32 PM
  #1  
Avi's Avatar
Avi
Thread Starter
Scooby Regular
 
Joined: Apr 2001
Posts: 5,084
Likes: 0
From: Manchester
Question

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]
Reply
Old Nov 14, 2003 | 02:54 PM
  #2  
sasim's Avatar
sasim
Used to work here!!
 
Joined: Jun 2000
Posts: 1,488
Likes: 0
From: Peterhead, Scotland
Post

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]
Reply
Old Nov 14, 2003 | 03:08 PM
  #3  
Avi's Avatar
Avi
Thread Starter
Scooby Regular
 
Joined: Apr 2001
Posts: 5,084
Likes: 0
From: Manchester
Post

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
Reply
Old Nov 14, 2003 | 03:14 PM
  #4  
SJ_Skyline's Avatar
SJ_Skyline
Scooby Senior
 
Joined: Apr 2002
Posts: 21,922
Likes: 2
From: Limbo
Smile

<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>
Reply
Old Nov 14, 2003 | 03:27 PM
  #5  
Avi's Avatar
Avi
Thread Starter
Scooby Regular
 
Joined: Apr 2001
Posts: 5,084
Likes: 0
From: Manchester
Post

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
Reply
Old Nov 14, 2003 | 03:43 PM
  #6  
judgejules's Avatar
judgejules
Scooby Regular
 
Joined: Nov 2000
Posts: 1,227
Likes: 0
Post

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
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
StickyMicky
Computer & Technology Related
3
May 22, 2004 03:02 PM
CodeKey@Lisan
Computer & Technology Related
11
Feb 20, 2004 05:23 PM
RichB
Computer & Technology Related
2
Nov 5, 2003 02:27 PM




All times are GMT +1. The time now is 10:20 AM.