Cyto Posted November 19, 2010 Share Posted November 19, 2010 Hey, I have this code: <script type="text/javascript"> $(document).ready(function(){ $('.rij2_content_fav').hide(); $('.mijngames').click(function() { $('.rij2_content_fav').slideToggle('slow', function() { $('.rij2_content_fav').animate({left: "-=232px", top: "+=50px"}); }); }); }); </script> The code works, does his job, but it toggles only one time. I need to refresh page to toggle again. How can i fix this, so that it toggles when i click several times? Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/219152-jquery-toggle-happens-only-one-time/ Share on other sites More sharing options...
Cyto Posted November 19, 2010 Author Share Posted November 19, 2010 someone? Quote Link to comment https://forums.phpfreaks.com/topic/219152-jquery-toggle-happens-only-one-time/#findComment-1136958 Share on other sites More sharing options...
.josh Posted November 19, 2010 Share Posted November 19, 2010 At face value and without seeing the context of this code, I'd say that every time you click, it "slides down" on first click, "slides up" on 2nd, etc... (because slideToggle() works by the current visibility state of the object is)...but then you have that animate() in there. EVERY time you click, it moves your item to the right 232px and down 50px. I think what you probably need to do is instead of using .click(), use .toggle() and make the first function be what you have now, and the 2nd one be the same thing, only reverse the order of slideToggle() and animate() and also reverse the animation properties. Something like... <script type='text/javascript'> $(document).ready(function() { $('.rij2_content_fav').hide(); $('.mijngames').toggle( function() { $('.rij2_content_fav').slideToggle('slow', function() { $('.rij2_content_fav').animate( { left : '-=232px', top: '+=50px' } ); }); }, function() { $('.rij2_content_fav').animate( { left : '+=232px', top: '-=50px' }, function () { $('.rij2_content_fav').slideToggle('slow'); } ); } ); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/219152-jquery-toggle-happens-only-one-time/#findComment-1136976 Share on other sites More sharing options...
Cyto Posted November 20, 2010 Author Share Posted November 20, 2010 I see, thx worked. Quote Link to comment https://forums.phpfreaks.com/topic/219152-jquery-toggle-happens-only-one-time/#findComment-1137001 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.