Issue
I have created a carousel with a previous and a next button that are always visible. These buttons have a hover state, they turn blue. On touch devices, like iPad, the hover state is sticky, so the button stays blue after tapping it. I don't want that.
I could add a
no-hover
classontouchend
for each button, and make my CSS like this:button:not(.no-hover):hover { background-color: blue; }
but that's probably quite bad for performance, and doesn't handle devices like the Chromebook Pixel (which has both a touchscreen and a mouse) correctly.I could add a
touch
class to thedocumentElement
and make my CSS like this:html:not(.touch) button:hover { background-color: blue; }
But that also doesn't work right on devices with both touch and a mouse.
What I would prefer is removing the hover state ontouchend
. But it doesn't seem like that is possible. Focusing another element doesn't remove the hover state. Tapping another element manually does, but I can't seem to trigger that in JavaScript.
All the solutions I have found seem imperfect. Is there a perfect solution?
Solution
You can remove the hover state by temporarily removing the link from the DOM. See http://testbug.handcraft.com/ipad.html
In the CSS you have:
:hover {background:red;}
In the JS you have:
function fix()
{
var el = this;
var par = el.parentNode;
var next = el.nextSibling;
par.removeChild(el);
setTimeout(function() {par.insertBefore(el, next);}, 0)
}
And then in your HTML you have:
<a href="#" ontouchend="this.onclick=fix">test</a>
Answered By - Sjoerd Visscher
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.