shortysbest Posted October 30, 2010 Share Posted October 30, 2010 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/ Share on other sites More sharing options...
trq Posted October 30, 2010 Share Posted October 30, 2010 http://api.jquery.com/toggle Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/#findComment-1128237 Share on other sites More sharing options...
shortysbest Posted October 30, 2010 Author Share Posted October 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/#findComment-1128242 Share on other sites More sharing options...
trq Posted October 30, 2010 Share Posted October 30, 2010 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)} }); }); Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/#findComment-1128256 Share on other sites More sharing options...
shortysbest Posted October 30, 2010 Author Share Posted October 30, 2010 Honestly i only skimmed it, I have been a bit busy between tv and stuff right now, but thanks for the code. However, it says there's a syntax error with the 3rd line, not sure why.? Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/#findComment-1128261 Share on other sites More sharing options...
trq Posted October 30, 2010 Share Posted October 30, 2010 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)} ); }); Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/#findComment-1128264 Share on other sites More sharing options...
shortysbest Posted October 30, 2010 Author Share Posted October 30, 2010 ahh yeah, i see, Thanks a lot, works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/217258-simple-if-statements-to-toggle-animate-effect/#findComment-1128266 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.