html - javascript marginLeft on image onload not working in Chrome -
i have gallery resizes image javascript in order keep original aspect ratio. document structure : stylesheet considering particular object following :
#thepicture {position:absolute;left:50%;height:100%;max-width:100%;}
then php build list of images menu,and recent 1 sets #thepicture
manipulated following javascript
function keepratio() { var height = document.getelementbyid('thepicture').height; var width = document.getelementbyid('thepicture').width; var origheight = document.getelementbyid('thepicture').naturalheight; var origwidth = document.getelementbyid('thepicture').naturalwidth; var ratio = origwidth / origheight; document.getelementbyid('thepicture').width = height * ratio; document.getelementbyid('thepicture').style.marginleft = - width/2; }
i call function once @ instance of window.onload
, @ every instance of selecting new image viewed , on ...thepicture').onload
now problem im having occurs in chrome : first there isnt image set thepicture (which made javascript function , because initial image in place after php constructed entire page.),on first click in menu select new image , nothing happens , on second click image appears out of intended position , , on third click , negative margin gets calculated,moving image in place.my page works fine in opera , mozilla.
Comments
Post a Comment