【问题标题】:How to delete :active with touchend如何删除:使用 touchend 激活
【发布时间】:2013-02-14 15:16:59
【问题描述】:

是否可以在 touchend 删除活动状态? 我想通过点击链接来设置链接的活动状态。当然,在我的移动设备中滚动时,我触摸的每个项目都会获得 :active 状态。所以滚动后所有元素都会突出显示。 我不想使用 .active-classes 进行 DOM 操作,我只想在滚动后删除活动状态 - 这可能吗?

a:active {
    background-color:blue;
}

$ctx.on("touchend", '.base a', function () {
    //removeActiveState
});

编辑:

我想拥有这个 - 但不是与类:

var activeSelector =  ".base a";   
$(document)
        .on("click mousedown touchstart", activeSelector, function () {
            $(this).addClass("active");
        })
        .on("mouseup mouseleave touchend", activeSelector, function () {
            $(this).removeClass("active");
        });

【问题讨论】:

  • 为什么不使用@media 为移动设备(手持设备)或分辨率较低的设备禁用:active?优点:不需要 JS
  • 我需要 :active 状态——它应该在滚动后被清除(我只是想通过点击它让它变成蓝色)

标签: jquery css mobile touch-event


【解决方案1】:

这是没有 CSS 类的代码。

var activeSelector =  ".base a";   
$(document)
    .on("click mousedown touchstart", activeSelector, function () {
        $(this).css('background-color', 'blue');
    })
    .on("mouseup mouseleave touchend", activeSelector, function () {
        $(this).css('background-color', 'white'); // or whatever color you want
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-10
    • 2015-12-01
    • 2020-12-15
    • 2015-02-12
    • 2014-11-29
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    相关资源
    最近更新 更多