【问题标题】:How to implement a blinds toggle effect with jQuery如何使用 jQuery 实现百叶窗切换效果
【发布时间】:2022-03-22 00:25:09
【问题描述】:

我正在尝试编写一个“百叶窗”函数,该函数将在 display:none 模式下关闭 DIV。看不见的 DIV 位于更宽的 DIV 内,包含盲触发器。

这个:

$(document).ready(function () {
    $("#toggle_blind").click(function () {
        $(this).toggle("fast");
    });
});

嗯,这会使按钮失明。如何将 DIV 添加到 $this?比如:

<div id="blind" class="wider_div">
   <h3 id="closeButton">Close</h3>
   <div style="display:none;" id="closeThis">
       <p>some text</p>
   </div>
</div>

如何使 H3 上的关闭按钮在每次点击时关闭/打开 CloseButton DIV?

【问题讨论】:

标签: javascript jquery toggle


【解决方案1】:

div 是 h3 的下一个兄弟,所以你可以使用 .next()

例如

$('#closeButton').click( function(){
  $(this).next().toggle();
});

【讨论】:

  • 其实还有一个问题:我可以在多个DIV中使用这个功能吗?尝试这样做,只为第一个 DIV 提供功能;其余的都麻木了。
  • 然后使用一个类和 .live 函数
【解决方案2】:

直接引用 div,你可以在它和 h3 之间放些别的东西。

$(document).ready(function()
{
    $("#closeButton").click(function()
    {
        $("#closeThis").toggle("fast");
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多