首页 > 解决方案 > 添加 will-change: transform 到 css 会导致图片消失

问题描述

我在将这个属性添加到 img 和 div 标签时遇到了一些关于 will-change: transform 的奇怪问题。基本上,我有一个 div 作为容器,其中包含一个 img 元素作为其子元素,并且我在 webkit 中滚动浏览这些图像。添加 will-change-transform 极大地提高了滚动性能,但是当您滚动时,您会间歇性地看到图像消失(或隐藏)。解决这个问题的任何答案都会很棒,因为我已经用尽了我从在线资源中尝试过的大部分解决方案。

我附上了 CSS 的代码片段:

“.cell”和“.pagNum”是 div 的类名属性。".pageNum" 是 img div(.cell) 顶部的页码 div。“.cell” div 包含 img 元素。

img {
    position: relative;
    -webkit-user-drag: none;
    will-change: transform;        
}

.cell {
    position: absolute;
    -webkit-border-radius: 0px;
    -moz-border-radius: 0px;
    will-change: transform;        
}

.pageNum {
    display: inline-block;
    position: absolute;
    top: 273px;
    background-position: center;
    text-align: center;
    line-height: 36px;
    min-width: 36px;        
    padding-left: 6px;
    padding-right: 6px;
    -webkit-border-radius: 3px;
    background-color: rgba(0, 0, 0, .50);
    color: white;
    font-size: medium;
    font-weight: bold;
    text-shadow: 0px 1px 0px #000000;
    left: 50%;
    margin: 0px 0 0 -32px;  
    will-change: transform;    

}

标签: javascriptjquerycsswebkit

解决方案


推荐阅读