Toggle button and Toggle visibility

前端 未结 1 848
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 04:02

I\'m using this jQuery to hide a DIV:

$(\"#slider\").click(function() {
    $(\".help\").slideToggle();
    $(\"#wrapper\").animate({ opacity: 1.0 },200).sli         


        
1条回答
  •  攒了一身酷
    2021-01-15 04:23

    You can hide one initially via CSS, then just toggle the two in your function, use this for CSS:

    .hide { dislay: none; } //Reverse if "Hide" should be the default button
    

    And this jQuery, using .toggle() (without arguments, it toggles visibility):

    $("#slider").click(function() {
      $(".help").slideToggle();
      $("#wrapper").animate({ opacity: 1.0 },200).slideToggle(200, function() {
        $("#slider img").toggle();
      });
    });
    

    This would toggle the visibility of both images...since one's hidden and you only have 2, it effectively swaps them. Also make sure to fix your alt/title attributes on the .show one for the screen reader folks :)

    0 讨论(0)
提交回复
热议问题