adam291086 Posted April 17, 2008 Share Posted April 17, 2008 I need to get an image width . The the problem is that that image is set behind some div tags which are set to display.none. They don't become display.block until later on. Any ideas how i can get this image width? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted April 19, 2008 Author Share Posted April 19, 2008 bump Quote Link to comment Share on other sites More sharing options...
jacksonmj Posted April 19, 2008 Share Posted April 19, 2008 document.getElementById("myimage").width and document.getElementById("myimage").height properties should give you the size of the image even with display:none. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted April 19, 2008 Share Posted April 19, 2008 Correct me if i am wrong but you want the actual size of the image am i right? There is 2 ways to solve that problem. 1. get the image width server side. 2. Get the image width when the page has fully loaded. I found a quick way to solve that using mootools /* Load Event fires when the whole page is loaded, included all images */ window.addEvent('load', function() { //in here you can execute your function to get your image width since the page has fully loaded }); Quote Link to comment Share on other sites More sharing options...
adam291086 Posted April 19, 2008 Author Share Posted April 19, 2008 @ DJ Kat I am new to javascript. That function will load when the window loads. How can i call on a varable out of that function. /* Load Event fires when the whole page is loaded, included all images */ window.addEvent('load', function() { var adam = document.getElementById("myimage").height }); how can i call upon adam later on Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted April 19, 2008 Share Posted April 19, 2008 I'm sure this will help you out this is a fully working example <script src="mootools-release-1.11.js"></script> <script> window.addEvent('load', function() { //the $("myimage") equals the document.getElementById("myimage") method mootools style var imageElement=$("myimage"); //create an image object var image= new Image(); //set the source of the image object image.src = $("myimage").src ; //alert the image height alert(image.height); }); </script> <img id="myimage" src="2426402588_f7486e0eb2.jpg" /> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.