javascript - jQuery 切换帮助

标签 javascript jquery

目前,单击 h2 标签可使用 slipToggle 切换 div。但是,我还尝试淡入和淡出 h2 标记中存在的 .hint_text_heading 。因此,最初,我至少尝试做的是,我向打开的 h2 标记添加一个 .active 类,然后在 .hint_text_heading 中淡入淡出。但是,当我关闭 div 时,我无法让 .hint_text_heading 淡出。

有什么建议吗?谢谢!

html

<h2 class="collapsible_head">This is a title.<span class="hint_text_heading">This is a hint.</span></h2>
<div>
  This is the toggled content.
</div>

jquery

$(document).ready(function(){
    $('span.hint_text_heading').hide();
    $('h2.collapsible_head').click(function() {
        $(this).next().slideToggle('slow');
        $(this).toggleClass('active');
        $('h2.active span.hint_text_heading').fadeIn();
    }).next().hide();
});

更新/

这是 jsFiddle 中的示例。如您所见,div 会切换,提示文本会淡入,但是,当 div 隐藏时,提示文本会保留。我试图让它淡出:

http://jsfiddle.net/UGHgx/

最佳答案

我认为这就是您想要的:

CSS:

span.hint_text_heading { display: none; }

jQuery:

$('h2.collapsible_head').click(function() {
    $(this).next().slideToggle('slow');
    //$(this).toggleClass('active');
    $('span.hint_text_heading', this).fadeToggle();
}).next().hide();

关于javascript - jQuery 切换帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818568/

相关文章:

jquery - 如何做bootstrap醉酒工具提示多行

javascript - JQuery .get 函数变量

javascript - 固定高度的div

javascript - 创建或删除新用户后更新用户列表

javascript - 对于 GraphQL,声明一个与 GraphQL "class"没有任何明显差异的支持模型 "Type"有什么好处或必要性?

javascript - JQuery 在运行时从 Checkbox 中检索 id

javascript - 使用 javascript 将变量推送到现有函数

Javascript:代码片段,无法让它工作(设置和读取cookie)

javascript - JS中删除字符右侧的文本

Jquery Json解析错误