简体   繁体   English

CSS3:悬停动画无法在Firefox上运行

[英]css3 :hover animation not working on firefox

I've created a CSS3 code that created a page flipping effect. 我创建了一个CSS3代码,该代码创建了页面翻转效果。

With three encapsulated div tags, first a div encapsulates the plain page and sets the perspective and transform-style. 使用三个封装的div标签,第一个div封装普通页面并设置透视图和转换样式。 The second div which contains the page is then rotated3d through the X-axis some degrees (I need an isometric perspective) and finally the inner div creates the page with a determinated color and size attributes. 然后,将包含页面的第二个div沿X轴旋转3d一定程度(我需要等轴测透视图),最后内部div创建具有确定的颜色和尺寸属性的页面。

This inner div has a :hover pseudo with an animation property, which indicates the transformation to do (in this case, flipping itself through the Y-axis). 此内部div具有带动画属性的:hover伪指令,该伪指令指示要执行的转换(在这种情况下,将自身通过Y轴翻转)。 For this purpouse there's as well a keyframe with a transformation-origin and the rotate3d attributes. 对于这个目的,还有一个带有转换原点和rotate3d属性的关键帧。

For some reason this works neat on Chrome webkit, but not on Firefox. 由于某种原因,它在Chrome Webkit上无法正常工作,但在Firefox上却无法工作。 In Chrome once the hover is done it keeps flipping until the page is totally turn over, even when the mouse is not anymore on the page due to the rotation. 在Chrome浏览器中,一旦完成悬停,它将一直翻转直到页面完全翻转,即使由于旋转鼠标不再在页面上。 In Firefox however it makes a small flip movement, but goes back to its initial state inmediately, even if the mouse is still on the page. 但是,在Firefox中,它会进行较小的翻转动作,但是即使鼠标仍然停留在页面上,它也会立即回到初始状态。

I've tried with animation-play-state: running; 我试过animation-play-state:运行; on the :hover pseudo, but neither works. 在:hover伪指令上,但都不起作用。

Any help? 有什么帮助吗? I can assure the -moz syntax is good as in -webkit. 我可以确保-moz语法与-webkit中一样。 Thanks!! 谢谢!!

Set width and height for the .box element and use it for hovering instead of the .rotateaux element: 设置.box元素的widthheight ,并将其用于悬停而不是.rotateaux元素:

.box {
    position: relative;
    width: 50px; 
    height: 90px;
    ...
 }

.box:hover .rotateaux {

Interestingly when using rotate3d Firefox rotates the element in the wrong direction as soon as specifying an angle >= 180° , ignoring the - sign, not sure what's the cause of this, so I've used rotateY in my example which Firefox handles correctly: 有趣的是,当使用rotate3d Firefox在指定角度> = 180°立即将元素沿错误的方向旋转,忽略了-符号,不确定是什么原因,因此我在示例中使用了Firefox能正确处理的rotateY

http://jsfiddle.net/V7Chp/ http://jsfiddle.net/V7Chp/

<div class="book">
    <div class="box">
        <div class="rotateaux"></div>
    </div>
</div>

.book {
    position: absolute;
    z-index: -1;
    top: 80px;
    right: 300px;

    -webkit-perspective: 300px;
       -moz-perspective: 300px;
            perspective: 300px;

    -webkit-perspective-origin: 0% 50%;
       -moz-perspective-origin: 0% 50%;
            perspective-origin: 0% 50%;
}

.box {
    position: relative;
    width: 50px; 
    height: 90px;

    -webkit-transform-style: preserve-3d;
       -moz-transform-style: preserve-3d;
            transform-style: preserve-3d;

    -webkit-transform: rotateX(70deg);
       -moz-transform: rotateX(70deg);
            transform: rotateX(70deg);
}
.rotateaux {
    position: relative;
    background: green;
    width: 50px; 
    height: 90px;

    -webkit-transform-origin: 0% 50%;
       -moz-transform-origin: 0% 50%;
            transform-origin: 0% 50%;
}

.box:hover .rotateaux {
    -webkit-animation: example 1.75s ease-in-out 0s infinite alternate;
       -moz-animation: example 1.75s ease-in-out 0s infinite alternate;
            animation: example 1.75s ease-in-out 0s infinite alternate;
}

@-webkit-keyframes example {
    from {
        -webkit-transform: rotateY(0deg);
    }
    to {
        -webkit-transform: rotateY(-180deg);
    }
}

@-moz-keyframes example {
    from {
        -moz-transform: rotateY(0deg);
             transform: rotateY(-180deg);
    }
    to {
        -moz-transform: rotateY(0deg);
             transform: rotateY(-180deg);
    }
}

@keyframes example {
    from {
        transform: rotateY(0deg);
    }
    to {
        transform: rotateY(-180deg);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM