jquery - How to use the function .toggle? -


how make reversing animation .animate? read in others places function .toggle, when used it, function starts automatically without "click". want (the function) begins when (or user) click it.

$(document).ready(function(){     $("#dae").toggle(         function(){             $("#dae").click(function(){                 $("#dae").animate({left:'50px', top:'100px'}, "slow");                 $("#dae").animate({opacity:0.1}, "slow");                 $("#dae").animate({opacity:1.0}, "slow");             });         }, function(){             $("#dae").click(function(){                 $("#dae").animate({opacity:1.0}, "slow");                 $("#dae").animate({opacity:0.1}, "slow");                 $("#dae").animate({left:'10px', top:'20px'}, "slow");             });         }     ) }); 

the problem is: when browser starts, div disappears.

you don't need "click" event in toggle. .toggle() based on click event.

so set such:

$("#dae").toggle(     function(){              $(this).animate({left:'50px', top:'100px'}, "slow");             $(this).animate({opacity:0.1}, "slow");             $(this).animate({opacity:1.0}, "slow");      }, function(){              $(this).animate({opacity:1.0}, "slow");             $(this).animate({opacity:0.1}, "slow");             $(this).animate({left:'10px', top:'20px'}, "slow");      } ) 

try above , see how works you. let me know if u have issues.

edit: note posted below not work in newer ver. of jquery no longer supports both functions. , valid point.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -