View Full Version : If statement to minimize and maximize image

07-16-2010, 04:47 AM
I am new to this and I am pretty lost, basically I want the div to start out completely minimized at 0% height and then when I click the button that calls the function it should increase the size to 100%, once it is maximized I want it to set the height back to 0% when the button is clicked again. Heres what I have so far. I can get it to minimize and maximize itself but I can't get the height set correctly.

<SCRIPT language="javascript">

var y = 100;
var q = 5;
var f = 0;
var g = 0;

function changeheight(){
e.style.height = y + 'px';


Can anyone help me out, or is there an easier way to do this?

07-16-2010, 10:31 AM
Replace 'yourElement' with the id of your image.

function changeHeight(){
var element = document.getElementById('yourElement');
if(element.style.height == "100%"){element.style.height = "0%";}
else{element.style.height = "100%";}

and set your images CCS style to your starting percentage as shown below.

<img src="abc.jpg" id="yourElement" style="height:100%;" />