简体   繁体   English

Chrome CSS过渡不透明度悬停问题

[英]Chrome CSS transition opacity on hover jumpy issue

I'm trying the most simple of opacity transitions in Chrome, but I'm finding that although often it is smooth, sometimes it jumps straight to opacity: 0 or opacity: 1, without transitioning. 我正在尝试使用Chrome中最简单的不透明过渡,但我发现尽管它通常很平滑,但有时会直接跳到不透明:0或不透明:1,而没有过渡。

Simplified version, just for webkit: 简化版,仅适用于Webkit:

<style type="text/css">
    .box{
        background-color: #ff0000;
        width:100px;
        height:100px;
        -webkit-transition: opacity 1s;
   }
   .box:hover{
       opacity:0;
   }
</style>

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

https://jsfiddle.net/bhydbakn/ https://jsfiddle.net/bhydbakn/

I find the best way to make it go wrong is to roll over, click, roll off, roll over again, wait for it to reach opacity: 0, then really slowly (pixel by pixel) roll off the image in a downwards direction. 我发现使它出错的最佳方法是滚动,单击,滚动,再次滚动,等待其达到不透明度:0,然后真正缓慢地(逐像素)沿向下方向滚动图像。 When I do this, half the time it will jump straight back to opacity:1 instead of transitioning smoothly. 当我这样做时,一半时间它会直接跳回到不透明度:1,而不是平稳过渡。

I'm Chrome 45.0.2454.101 m on Windows 7. Have tested on a colleague's PC and found the same issue. 我是Windows 7上的Chrome 45.0.2454.101 m。已经在同事的PC上进行了测试,发现了同样的问题。

Here's a video of it going wrong. 这是一段出错的视频。 It works until about half way: http://webm.host/41dce/ 它可以工作到大约一半: http : //webm.host/41dce/

Here's an updated code: 这是更新的代码:

<style>
.box {
    background-color: #ff0000;
    width: 100px;
    height: 100px;
    opacity: 1;
    -webkit-transform: translateZ(0);
    -webkit-transition: opacity 1s ease-in-out;
}
.box:hover {
    opacity: 0;
}
</style>

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

Note the default opacity added to your .box container, an easing function and default hardware acceleration by using a transform declaration. 请注意添加到您的.box容器的默认不透明度,缓动函数和使用转换声明的默认硬件加速。

Note that I cannot reproduce your issue. 请注意,我无法重现您的问题。 It might be a browser thing. 可能是浏览器问题。

This should fix your issue 这应该可以解决您的问题

$(".box").mouseenter(
  function(){
    $(this).animate({opacity:'0'},'1000')
  });
$(".box").mouseleave(
  function() {
    $(this).animate({opacity:'1'},'1000')
  });

https://jsfiddle.net/bhydbakn/2/ https://jsfiddle.net/bhydbakn/2/

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

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