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?
The :focus pseudo-class applies when an element is in a state that is ready to be interacted with, i.e. it has the focus of the input device.
The :active CSS pseudo-class represents an element (such as a button) that is being activated by the user. When using a mouse, "activation" typically starts when the user presses down the primary mouse button.
A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :hover selector to style links when you mouse over them.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With