jQuery fadeIn and fadeOut - swapping divs

后端 未结 6 1132
挽巷
挽巷 2021-01-25 19:33

I\'m new to jQuery and javascript in general but am plugging my way through thanks to sites like these.

I have a page with six hidden divs that are called with correspon

6条回答
  •  走了就别回头了
    2021-01-25 20:19

    The best way would be to use http://api.jquery.com/toggle/

    Toggle lets you the animation for one

    $('#clickme').click(function() {
      $('#book').toggle('slow', function() {
        // Animation complete.
      });
    });
    

    As for truely Shortening the code I would use a class identifier for your panels.

    Identify panel groups like

    $("#panel3").fadeOut("slow", function() {
    $("#panel4").fadeOut("slow", function() {                       
    $("#panel5").fadeOut("slow", function() {
    $("#panel6").fadeOut("slow", function() {
    

    and then assign the associated HTML elements a class like

    Your jQuery can now be $(".panelGroup1").fadeOut...

    The . class selector for jQuery and the # is the id Selector.

    Check out selectors and you can do a bunch of other crazy things

    http://api.jquery.com/?ns0=1&s=Selector&go=

提交回复
热议问题