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
    2,106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery Toggle with changing open ena close button

    I have the following function to slideToggle different divs:
    Code:
        $(document).ready(function() {
          $( "#toggle a" ).click(function(e){
    	    e.preventDefault();
    		$("#languages, .logo, .fb, #content").slideToggle("slow");
    	  });
        });
    By default I use a arrow (up) for the closing action. Css:
    Code:
    #header #toggle a  {
      width: 2.5rem;
      height: 2.5rem;
      display: block;
      color: #FFF;
      text-decoration: none;
      background: url("../images/site/close.png") 0 0 no-repeat;
     }
    What I would like to accomplish is that the close.png will be replaces with open.png. You can find a example of the page here. What should I change in the function to make those images swap?

    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,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi donboe,

    Hard code both images into your page and stick them in a div.
    You can then pass slideToggle a callback which will execute when the animation is complete.
    Within this callback, you can toggle the images using .toggle()

    I made a similar demo for someone else recently.
    You can find it here.

    HTH

  3. #3
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works great Pullo Thanks a lot
    “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
  •