SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    1,967
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I keep struggling with the .animate function

    I keep stuggling with the animate function. in combination with the .toggle function. I simply try to make a div slide from right to left and visa versa on click. This is what I have:

    Javascript:
    Code:
    	var w = $('.content').width();
    	
      $('#toggle').toggle(function() {
        $('div.content').animate({left: -600}, 600, function(){
    			$('#toggle').text("open");
    		});
    		return false;
      }, function() {
        $('div.content').animate({left: 0}, 900, function(){
    		  $('##toggle'').text("close");
    		});
    		return false;
      });
    HTML
    Code:
    <div id="content" class="content">
    	<div class="header">
      	<div class="close"><a href="##" id="toggle">Close</a></div>
      	<h1>Title</h1>
    	</div>
    </div>
    When opening the page the content div slide automatically to the left and the toggle anchor slides to the right. What am I doing wrong, and can someone please explain me the .animate/.toggle functions in more detail.

    Thank you in advance
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    Grüße aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,353
    Mentioned
    179 Post(s)
    Tagged
    9 Thread(s)
    Hi donboe,

    Which version of jQuery are you using?
    jQuery's Toggle Event function has been removed as part of version 1.9. which could account for your error.

  3. #3
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    1,967
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh my. That was it indeed. I was struggling the entire morning. Thank you so much Pullo.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •