CSS转换在鼠标移动时失去悬停状态

时间:2012-12-07 14:59:30

标签: html css css3 hover css-transforms

我有以下HTML / CSS标记,它应该转换div状态的:hover元素。

将鼠标悬停在div元素上时,会正确添加:hover个样式。但是在鼠标移动时,这些样式会丢失,直到鼠标停止移动。

为什么会这样?


HTML:

<div class="module">
sdfsdf
<br><br>
<img src="http://placekitten.com/100/100" />
</div>​

CSS:

.module
{
    width:200px;
    height:200px;
    background:blue;
    margin:10px;
    color:#fff;
    padding:10px;
}

.module:hover
{
    -webkit-transform-origin:50% 50%;
    -webkit-transition:-webkit-transform 0.08s;
    -webkit-font-smoothing:antialiased;
    -webkit-transform:perspective(800px) rotateX(0deg) rotateY(0deg) translateZ(-20px);

}​

-- See jsFiddle Demo --

注意:我的演示和CSS目前只适用于webkit。

我正在谷歌Chrome版本23.0.1271.95 m上复制此问题

3 个答案:

答案 0 :(得分:0)

我使用Chrome也一样。这解决了它:

<div class="container">
<div class="module">
    <img src="http://placekitten.com/100/100"> 
</div>
</div>

和css

.module
{
width:200px;
height:200px;
background:blue;
color:#fff;
padding:10px;
}

.container:hover .module
{
-webkit-transform-origin:50% 50%;
-webkit-transition:-webkit-transform 0.08s;
-webkit-font-smoothing:antialiased;
-webkit-transform:perspective(800px) rotateX(0deg) rotateY(0deg) translateZ(-20px);

}​​​​​​​​​​​​​​​​​​​

答案 1 :(得分:0)

似乎问题与负z值有关,因为将其更改为translateZ(20px);可以正常工作。如果您不想使用额外的div,则可以将-webkit-transform-style: preserve-3d;添加到body

这是更新后的jsfiddle

希望有所帮助!

答案 2 :(得分:0)

尝试一下

我将其放入容器div中。将鼠标悬停在容器上,并将.module上的指针事件设置为none。删除了不必要的东西。如果需要,您仍然可以将-webkit-添加到其中的某些内容中。对我来说似乎没有必要。

注意,我将过渡移到了悬停代码之外 `

* {
    box-sizing: border-box;
}

.container {
    width: 200px;
    height: 200px;
    margin: 10px;
    border: 1px solid black;
    perspective: 800px;
}

.module {
    width: 200px;
    height: 200px;
    background: blue;
    color: #fff;
    padding: 10px;
    pointer-events: none; 
    transition: transform 0.08s;
}

.container:hover .module {
    transform: translateZ(-20px);
}
        <div class="container">
            <div class="module">
                sdfsdf
                <br />
                <br />
                <img src="http://placekitten.com/100/100" />
            </div>​
        </div>

`

相关问题