Jump to content

Recommended Posts

I have a problem in that I'm trying to get an animation that slides and panel out horizontally, and then slides it back, controlled by clicking some cover art, this should be toggled.

 

The problem is that when the picture is clicked, jQuery does both the normal toggle animation (which I don't want) and plays my custom animation.

 

You can see the problem by clicking the album art; when in the text is hidden and the art is clicked, it toggles the text in, then animates it away. Another click (the text should be showing..) animates the text in, then animates it away.  Here's my code:

 

$(document).ready(function() {

$("#cdinfo").hide();

$('#cdcase').click(function() {
	$('#cdinfo').toggle(function() {
		$('#cdinfo').animate({ 
	        width: "250",
	      }, 1500 );
	    $('#cdinfo').animate({ 
	        width: "0",
	      }, 1500 );
	return false;
	});
});
});

 

This is my first bit of jQuery myself, hoping to learn a lot.

Link to comment
https://forums.phpfreaks.com/topic/158480-solved-jquery-toggling-an-animation/
Share on other sites

Hmm...

 

Well, the toggle event is essentially a specialized click event (http://docs.jquery.com/Events/toggle#fnfn2fn3.2Cfn4.2C...).  So, why not remove the outer-most click event?

 

$(document).ready(function()
{
   $("cdinfo").hide();

   $('#cdcase').toggle(
   function()
   {
      $('#cdinfo').animate({width: "250"}, 1500);
   },
   function()
   {
      $('#cdinfo').animate({width: "0"}, 1500);
   });
});

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.