Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS animation for both mouse hover and touch (iOS)

Here is plnkr example.

Basically there is a style like that

.hover-block {
    -webkit-transition: all 1s linear;
            transition: all 1s linear;      

}

.hover-block:active {
  pointer-events: none;
    -webkit-transform: scale(1.5);
            transform: scale(1.5);
}

.hover-block:hover {
    -webkit-transform: scale(1.5);
            transform: scale(1.5);
}

I'm seeking to support evergreen and IE10/11, Chrome for Android (4.4+), Mobile Safari (iOS 7+), and it shouldn't hurt other touch events (swipe scrolling).

It seems to work as intended on Android and Chrome device emulation, non-sticky transform on touch is desired behaviour.

But somehow this plunker doesn't work on iOS webkit (iOS 8, all browsers), it does nothing on touch. I'm quite sure that exactly the same approach (block element, :active with pointer-events: none plus :hover) worked for me in iOS 8 before. How can it be fixed?


It looks like empty touchstart/touchend JS event handler or ontouchstart/ontouchend attribute can activate touch behaviour on iOS (can't be sure but it is possible that it happened to me before). Is it a known fix for the problem or there are less hacky ones, which iOS versions are affected?

like image 352
Estus Flask Avatar asked Jun 16 '15 11:06

Estus Flask


People also ask

Can I add 2 animation in CSS?

You cannot play two animations since the attribute can be defined only once.

Does Safari support CSS animation?

Safari supports two types of CSS animation: transition animations and keyframe animations.

What is WebKit in CSS animation?

WebKit now supports explicit animations in CSS. As a counterpart to transitions, animations provide a way to declare repeating animated effects, with keyframes, completely in CSS. With a recent nightly build, you can see the above animation in action.


1 Answers

In your html, instead of <body>, do <body ontouchstart=""> Or in html5, just <body ontouchstart>

like image 50
lucian Avatar answered Oct 15 '22 04:10

lucian