Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/219152-jquery-toggle-happens-only-one-time/
Share on other sites

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>

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.