Floating Image
Version 2.00
written by Gerald Holdsworth

Following on from the Floating Image, this does the same thing but using CSS to keep the image still. The Javascript is simply there to centralise the image on the page and report the co-ordinates of the position.

Click here for a demo

Stylesheet for 'Floating Image':
Javascript for 'Floating Image':
// You will need to add onload="setUpVars()" into the BODY tag of the HTML document
function setUpVars()
 var el=document.getElementById('floater');
 var X=(getViewWidth()-el.offsetWidth)/2;
 var Y=(getViewHeight()-el.offsetHeight)/2;
function getPosition(id,x)
 var obj=document.getElementById(id);
 var topValue= 0,leftValue= 0;
  leftValue+= obj.offsetLeft;
  topValue+= obj.offsetTop;
  obj= obj.offsetParent;
 if (x==0) finalvalue = topValue; else finalvalue=leftValue;
 return finalvalue;
function getViewWidth()
 if (typeof window.innerWidth!='undefined')
 else if (typeof document.documentElement!='undefined' && typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0)
 else w=document.getElementsByTagName('body')[0].clientWidth;
 return w;
function getViewHeight()
 if (typeof window.innerHeight!='undefined')
 else if (typeof document.documentElement!='undefined' && typeof document.documentElement.clientHeight!='undefined' && document.documentElement.clientHeight!=0)
 else w=document.getElementsByTagName('body')[0].clientHeight;
 return w;

If you would like to email me, put gerald@ in front of the domain name, insead of www..
©2011-2020 Gerald Holdsworth IT Services