jQuery fadeIn and fadeOut - swapping divs

后端 未结 6 1133
挽巷
挽巷 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:27

    You could do something like

    function fadeElementIn(fadedElement) {
        $("[id^=panel]").fadeOut("slow");
        $(fadedElement).fadeIn("slow");
    }
    

    And then:

    $(document).ready(function(){
    
        $("#link1").click(fadeElementIn($("#panel1")));
        $("#link2").click(fadeElementIn($("#panel2")));
        $("#link3").click(fadeElementIn($("#panel3")));
        $("#link4").click(fadeElementIn($("#panel4")));
    }
    

    remember to adjust your elements positioning if you want the one that's fading out and the one that's fading in to occupy the same space

    cheers

提交回复
热议问题