Lol, either I'm having tremendously bad luck today, or something.... I couldn't get this to work. Is it possible that "t.style.left....." etc should be "e.style.left...."?
If I change "t" to "e" and then click on the word 'Test', it just disappears.
Quote:
Originally Posted by wirehopper
HTML Code:
<body id="bd">
<span id="test" onclick="bork(this)" style="position:absolute">Test</span>
<script type="text/javascript">
r=document.getElementById('bd').getClientRects().item(0);
function bork(e)
{
sw=screen.width;
sh=screen.height;
cr=r.right;
cl=r.left;
cw=cr-cl;
ct=r.top;
cb=r.bottom;
ch=cb-ct;
t.style.left=(cw/2-(sw-cw)/2).toString()+"px";
t.style.top=(ch/2-(sh-ch)/2).toString()+"px";
}
</script>
Tested in FF3, IE7
|