触发“:active”触摸屏上的伪类

发布于 2024-09-26 00:19:32 字数 188 浏览 0 评论 0原文

我目前正在开发一个 JavaScript 应用程序,该应用程序将部署在以 kiosk 模式运行 Chrome 的触摸屏 kiosk 上。

我注意到,当我使用鼠标单击界面上的按钮时,“:active”伪类应用的样式在鼠标按下时可见。我的问题是,通过触摸屏幕触发的同一按钮不会触发活动状态。

有没有办法让触摸事件的行为与鼠标单击相同?

I'm currently developing a JavaScript application which will be deployed on a touchscreen kiosk running Chrome in kiosk mode.

I've noticed that when I use a mouse to click the buttons on the interface, the styles applied by the ":active" pseudo class is visible when the mouse is down. My problem is that the same button triggered by touching the screen does not trigger the active state.

Is there a way to make a touch event behave the same way as a mouse click?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜血缘 2024-10-03 00:19:32

假设 CSS :active 伪类不起作用,您可能需要使用 DOM 事件。

“mousedown”和“mouseup”事件适用于触摸屏吗?假设他们这样做,你可以尝试这样的事情:

addEventListener("mousedown", function (event) {
    if (event.target.setAttribute) {
        event.target.setAttribute("data-active", "");
    }
}, true);

addEventListener("mouseup", function (event) {
    if (event.target.removeAttribute) {
        event.target.removeAttribute("data-active");
    }
}, true);

然后在你的 CSS 中,将 :active 替换为 [data-active],如下所示:

div[data-active] {
    /* blah blah */
}

我不认为这会完全一样......你可能需要做一些技巧例如,让子元素正常工作。

Assuming the CSS :active pseudo-class isn't working, you'll probably need to use DOM events.

Do the "mousedown" and "mouseup" events work with touchscreens? Assuming they do, you could try something like this:

addEventListener("mousedown", function (event) {
    if (event.target.setAttribute) {
        event.target.setAttribute("data-active", "");
    }
}, true);

addEventListener("mouseup", function (event) {
    if (event.target.removeAttribute) {
        event.target.removeAttribute("data-active");
    }
}, true);

Then within your CSS, replace :active with [data-active], like so:

div[data-active] {
    /* blah blah */
}

I don't think this will work quite the same... you may need to do some trickery to get child elements to work correctly, for instance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文