jquery - 单击并悬停 - 单击时显示文本?

标签 jquery html css mouseevent toggle

目前这一切工作正常,除了当点击元素时内部文本不显示。它仅适用于 mouseovermouseleave。我试过在 mouseleave 上使用 unbind 但这似乎不起作用。

如何让它在点击元素时起作用?

这是我的 fiddle .

$('.item').on({
    mouseover: function() {
        if ($(this).closest('.timelineTile').hasClass("clicked")) {
            $(this).parent('.highlight').addClass("hovered");
            $(this).siblings('.inner').addClass("display");
        }
    },
    mouseleave: function() {
        if ($(this).closest('.timelineTile').hasClass("clicked")) {
            $(this).parent('.highlight').removeClass("hovered");
            $(this).siblings('.inner').removeClass("display");
        }
    }
});

$('.highlight').on('click', '.item', function(e) {
    if ($(this).closest('.timelineTile').hasClass("clicked")) {
        e.stopPropagation();
        $('.item').not(this).removeClass('canceled');
        $(this).parent().toggleClass('canceled');
        $(this).parent().removeClass('hovered');
        $(this).siblings('.inner').removeClass("display");

    }
});

最佳答案

查看 this 是否是您要查找的内容... updated Fiddle

关于jquery - 单击并悬停 - 单击时显示文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26341426/

相关文章:

javascript - PHP 编程错误(无法运行 while 循环)

javascript - 在 JSON 字符串中分隔 PHP 变量

javascript - 将 JSON 字符串转换为 Javascript 数组

javascript - $ ("#example").DataTable() 返回空数组

html - head 标签在 HTML 代码中的位置重要吗?

javascript - 根据点击次数增加值(value)

html - 基于百分比的 margin-top 和 height 不能一起工作

html - 增加表格行之间的间距

javascript - AngularJS ng-models 在转发器中使用原型(prototype)变量

javascript - 无法在 Chrome 上看到控制台错误