【问题标题】:How do I remove flickering line when using css tranform:scale?使用 css transform:scale 时如何删除闪烁的线条?
【发布时间】:2016-06-04 15:30:36
【问题描述】:

当我将鼠标悬停在图像上时,我一直在尝试消除这种难看的闪烁。我尝试将 -webkit-backface-visibility: hidden; 与 :hover 本身一起添加到悬停元素,但似乎无法动摇它。似乎问题只在 Chrome 和 Safari 上。 网址:http://best-law-firm-sites.com/lawpromo12/

.col-sm-4 {
    width: 33.3333%;
    float: left;
}
.panel-wrap {
    height: 100% !important;
}
.panel-wrap .col-sm-4 {
    padding: 0;
}
.hovereffect {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    cursor: default;
}
.hovereffect .overlay {
    width: 100%;
    height: 100%;
    position: absolute;
    overflow: hidden;
    top: 0;
    left: 0;
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
}
.hovereffect h2,
.hovereffect img {
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
}
.hovereffect img {
    display: block;
    position: relative;
    -webkit-transform:  scale(1.001);
    -ms-transform:  scale(1.001);
    -moz-transform:  scale(1.001);
    -o-transform:  scale(1.001);
    transform:  scale(1.001);
}
.hovereffect:hover img {
    -webkit-transform: scale(1.17);
    -ms-transform: scale(1.17);
    -moz-transform: scale(1.17);
    -o-transform: scale(1.17);
    transform: scale(1.17);
}
.hovereffect h2 {
    bottom: 10%;
    color: #fff;
    font-size: 30px;
    font-weight: 700;
    padding: 10px 10px 10px 17px;
    position: absolute;
    text-align: left;
    text-shadow: 2px 3px 6px rgba(0, 0, 0, 1);
    text-transform: uppercase;
}
.hovereffect h2::after {
    display: block;
    content: "";
    height: 4px;
    width: 75px;
    background: #BCA474;
    margin: 20px 0 0;
    box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.6);
}
.hovereffect a.info {
    display: inline-block;
    text-decoration: none;
    padding: 7px 14px;
    text-transform: uppercase;
    color: #fff;
    margin: 50px 0 0 0;
    background-color: transparent;
    -webkit-transform: scale(1.5);
    -ms-transform: scale(1.5);
    transform: scale(1.5);
    -webkit-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
    font-weight: normal;
    height: 100%;
    width: 85%;
    position: absolute;
    top: 0;
    left: 0;
    padding: 70px;
}
.hovereffect:hover a.info {
    -webkit-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
}
<div class="col-sm-4 panel-1">   
<div class="hovereffect">
        <img class="img-responsive" src="http://best-law-firm-sites.com/lawpromo12/wp-content/uploads/2016/02/panel1.jpg" alt="">
        <div class="overlay">
           <h2>Family Law</h2>
           <a class="info" href="services/family-law/"></a>
        </div>
    </div>
  </div>

  <div class="col-sm-4 panel-2">   
<div class="hovereffect">
        <img class="img-responsive" src="http://best-law-firm-sites.com/lawpromo12/wp-content/uploads/2016/02/panel.jpg" alt="">
        <div class="overlay">
           <h2>Estate Planning</h2>
           <a class="info" href="services/estate-planning/"></a>
        </div>
    </div>
  </div>

  <div class="col-sm-4 panel-2">   
<div class="hovereffect">
        <img class="img-responsive" src="http://best-law-firm-sites.com/lawpromo12/wp-content/uploads/2016/02/panel.jpg" alt="">
        <div class="overlay">
           <h2>Wills & Trusts</h2>
           <a class="info" href="services/wills-trusts/"></a>
        </div>
    </div>
  </div>

【问题讨论】:

  • 我在 Windows 10 上的 Chrome 和 Firefox 中对此进行了测试,但无法重新创建...您正在测试哪种浏览器/操作系统组合?
  • 我看不到您指的闪烁,您使用的是较旧的操作系统/浏览器吗?
  • 在查看堆栈溢出中的 sn-p 时,我在 Windows 7 上的 Chrome 中看到一条奇怪的线,但在您链接到的演示站点上却没有。
  • 清理一下样例就好了:sscce.org

标签: css css-animations flicker


【解决方案1】:

您可以通过将transform scale 属性增加到 1.001 来解决此问题:

.hovereffect img{transform: scale(1.001);}

【讨论】:

    【解决方案2】:

    过去,当我使用背面可见性黑客来欺骗浏览器使用 3d 管道时,我也遇到过类似的奇怪行为。还有其他方法可以“欺骗”浏览器使用 3d 管道,例如:

    .class{
        transform: translate3d(0,0,1);
    }
    

    【讨论】:

    • 为什么要评论?
    • 我重新创建了问题,如我留下的评论中所示。 “你可以试试”是一个很好的答案,因为它在过去为我解决了这个问题。
    • 当原始问题的形式是“我正在做这个骇人听闻的未定义的事情”时,很难回答“我确信其他骇客不会表现出相同的未定义行为”
    • 这无助于其他任何人来到此页面并略读以找到答案,这就是 StackOverflow 的全部意义。
    • 你在什么浏览器上重新创建了这个?我在多台机器上尝试了一堆,但没有重新创建。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多