jquery - Issuing centering dynamically sized object with JavaScript in Prototype -


i've got edge edge video resizes browser dynamically, center on page now. because video's size varies, need javascript.

you lovely folks helped me correct syntax major issue had, i'm still not seeing results i'm looking for.

the theory function measures browser viewports width , height , video's width , height, subtracts video browser, divides 2 , applies left , top values in css. video set position:absolute in div that's set position:fixed.

update:

with @guffa's advice in mind, defined video variable , applied styles directly. code sound , shows no errors, i'm not seeing result. honestly.. been trying @ few days , can't figure out.

update:

tested code commenting out lines 4 , 5 below , adding in vid.style.left = (500) + "px"; , worked.. tested vid.style.left = (windowwidth) + "px"; , worked... means code failing @ parseint(vid.style.width,10). logic of line calculate video's existing width... what's issue?

test page: http://kzmnt.com/test/

lines 55 through 59 in question (reformatted reading ease):

var windowwidth = document.viewport.getwidth(); var windowheight =  document.viewport.getheight(); var vid = document.getelementbyid('live'); vid.style.left = ((windowwidth - parseint(vid.style.width,10)) / 2) + "px"; vid.style.top = ((windowheight - parseint(vid.style.height,10)) / 2) + "px"; 

ideas?

thanks help!

the error mismatching parentheses.

just adding parentheses won't make code work, though. code dividing element 2 , subtracting window width, place element halfway outside window.

you should first subtract element width window width, divide two:

this.style.left = ((windowwidth - parseint(this.style.width,10)) / 2) + "px"; this.style.top = ((windowheight - parseint(this.style.height,10)) / 2) + "px"; 

edit:

as width , height styles not set on video element, have pick size calculated it. it's put in width , height html properties, can values , parse them.

element.style.left = ((windowwidth - parseint(element.width)) / 2) + "px"; element.style.top = ((windowheight - parseint(element.height)) / 2) + "px"; 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -