Tuesday, February 16, 2010

Programmer - javascript horizontal center

Programmer Question

Hello, Im trying to use java script to center a page horizontally.



So far i got this:



<body onload="scrollBy((document.body['scrollWidth'] - 0) / 2, 0)">


It kinda works, but not very good. I have a large width flash component
that I need centered when the page loads and also after any click on the internal buttons.



I was thinking of making a call from flash to a javascript that would scroll the page to an HTML anchor.



Something along the lines of:



 <script type="text/javascript">
function pageMid() {
window.location.href="#mid"
}
</script>


But the anchors don't align to middle.



Any ideas?



Thank you.

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails