Reputation: 22045
In Safari on iOS, is there a CSS pseudo class for when a user is touching an element? Or do I have to use javascript?
Similar to how :hover works on desktop computers, it would be active while the finger is touching the element, and then be inactive as soon as the user stops touching the element.
Upvotes: 1
Views: 5284
Reputation: 3471
Answered here: https://stackoverflow.com/a/8877902/520129
<body ontouchstart=""> ... </body>
Applied just once, as opposed to every button element seemed to fix all buttons on the page. Alternatively you could use this small JS library called '[Fastclick][1]'. It speed up click events on touch devices and takes care of this issue too.
[1]: http://assanka.net/content/tech/2011/08/26/fastclick-native-like-tapping-for-touch-apps/
Upvotes: 1
Reputation: 724092
CSS currently does not define any user-action pseudo-classes for touch paradigms.
You'll have to listen for events and handle them accordingly with JavaScript. In fact, Apple recommends this; see Handling Events in the Safari Web Content Guide for details. You'll want to look at the touchstart
, touchend
, touchmove
and touchcancel
events, for example.
Upvotes: 2