center

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Anyone know a crossbrowser way to display a variable object (ie. an image) in the center of the browser screen without using frames?

Thanks in advance!

Shakespeare: onclick || !(onclick)

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Jack,

If my sense of geometry is still good (and if I'm awake enough Smiling, this should work:

var winWidth = ( (document.layers) || (document.getElementById)) ? window.innerWidth : document.body.clientWidth;

var winHeight = ( (document.layers) || (document.getElementById)) ? window.innerHeight : document.body.clientHeight;

var winXCenter = winWidth/2;
var winYCenter = winHeight/2;

var imgWidth = imgObj.width;
var imgHeight = imgObj.height;

var xCenter = winXCenter - (imgWidth/2)
var yCenter = winYCenter - (imgHeight/2)

Vinny

Where the world once stood
the blades of grass cut me still

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

I was thinking about that one... but didn't know precisely and I was too lazy to check and work it out Laughing out loud

thanx!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.