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;
}

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)}
  });
});

Link to comment
Share on other sites

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)}
  );
});

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.