Jump to content

simple if() statements to toggle animate effect


shortysbest

Recommended Posts

This code sort of works, right now it expands the div from 355px wide and 200px height to 711px wide, 400px high. Then When i click on the div again to put it back to 355px by 200px (2nd if statement code) it goes back, however when i click on it again to expand it expands, and immediately changes the size back to 355x200 without me clicking it, How could i "toggle" this animate effect so it goes to the larger size, then back to original size?  both onclick.

 

 

function img_expand()
{
var done = false;

if (done==false){
$(".productphoto").animate({width: "711px", height: "400px",},100)
var done = true;
}

if(done==true){
$('.productphoto').click(function(){$(".productphoto").animate({width: "355px", height: "200px",},100)	});
var done = false;
}

}

Thanks, I know how to do this toggle, if i just want it to go from no div being there, to it opening, but i want it to start at 355px by 200px, and onclick go to 712px by 400px, and then onclick again back to 355px by 200px, and repeat the same thing each time you click.

 

right now after the 3rd click it expands, and immediately goes back to smaller size.

Did you look at the link I gave you?

 

$(document).ready(function() {
  $('.productphoto').toggle({
    function() {$(this).animate({width: "711px", height: "400px"},100)},
    function() {$(this).animate({width: "355px", height: "200px"},100)}
  });
});

Sorry, its not like I test code I post here.

 

It was a simple mistake.

 

$(document).ready(function() {
  $('.productphoto').toggle(
    function() {$(this).animate({width: "711px", height: "400px"},100)},
    function() {$(this).animate({width: "355px", height: "200px"},100)}
  );
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.