将鼠标悬停在 Safari 中的 CSS 过渡上会使某些字体颜色变亮

发布于 2024-12-13 07:39:14 字数 304 浏览 2 评论 0原文

在我的 CSS 中,我定义了一个类的转换。由于某种原因,当我将鼠标悬停在带有过渡的类上时,transition-duration 由于某种原因会改变其他地方的字体颜色(形成占位符和某些链接)。 (据我所知,这种情况只发生在 Safari 中。)

这是一个 jsFiddle,它显示了我正在谈论的内容:

http: //jsfiddle.net/EJUhd/

有谁知道为什么会发生这种情况以及如何防止它?

In my CSS I defined a transition for a class. For some reason, when I hover over the class with the transition, the transition-duration for some reason alters the font color elsewhere (form placeholders and certain links). (This happens only in Safari as far as I can tell.)

Here's a jsFiddle that shows what I'm talking about:

http://jsfiddle.net/EJUhd/

Does anyone know why this occurs and how I can prevent it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

你在看孤独的风景 2024-12-20 07:39:14

我正在为类似的问题而苦苦挣扎。
对我来说,整个页面的随机链接明显变得粗体(显然与 OSX 和 Safari 中的抗锯齿有关,因为 Chrome(在 Windows 7 和 OSX 中)以及 Windows 中相同版本的 Safari 运行良好。

解决方案是不明显,并且根据您正在做的事情可能不是最佳的,但添加这行代码解决了问题:

-webkit-transform: translateZ(0);

这基本上会触发 GPU 执行动画,并且文本在我的网站中不再有伪影 请注意,它不是。总是适合使用它,因为它可能使用更多的电池寿命并使用更多的资源,但是有时,它使用较少,所以基本上在添加它时检查性能

而不< 。 /em> :hover 动画状态

img { -webkit-transform: translateZ(0); }

与 on: 相反,

img:hover { /* not here */ }

另一个非常积极的副作用是,根据您正在执行的动画,它可能会通过 GPU 变得更流畅,因此您不会获得您提到的断断续续的动画。在你的后续帖子中,动画更加无缝。野生动物园。我正在对图像进行 120% 缩放和 5 度旋转,同时出现一些框阴影。不幸的是,在我的情况下,它并没有减少 CPU 使用率。

I was struggling with a similar issue.
For me, random links throughout the page became apparently bold (clearly something to do with OSX and anti-aliasing in Safari, as Chrome (in windows 7 and OSX) as well as the same version of Safari in Windows worked fine.

The solution is not obvious, and depending on what you are doing might not be optimal, but adding this line of code fixed the issue:

-webkit-transform: translateZ(0);

This basically triggers the GPU to do animation, and the text no longer had artifacts in my site. Do note that it's not always appropriate to use it, as it may use more battery life and use more resources. Sometimes however, it uses less, so basically check the performance when you add it.

You add this to the normal state not the :hover animated state.

img { -webkit-transform: translateZ(0); }

As opposed to on the:

img:hover { /* not here */ }

The other very positive side effect is that depending on the animation you are doing, it might be smoother through the GPU. So you won't get the choppy animation you mention in your follow up post. In my case, the animation was more seamless in safari. I was doing a 120% scale and 5 degree rotation of an image with some box-shadow appearing at the same time. In my situation, it did not reduce CPU usage unfortunately.

谜兔 2024-12-20 07:39:14

我没有找到与我遇到的问题更相关的主题,但这与上述问题相关。所以,可能对某些人有帮助。

用两个词来说:我有一些容器(弹出窗口),里面有一些元素。
出现的方式如下:容器背景通过不透明度逐渐变暗,内部元素按比例放大(就像从后面靠近我们一样)。一切都在任何地方都运行良好,但在 Safari (Mac/Win/iPhone) 中则不然。 Safari“最初”显示了我的容器,但它以某种奇怪的方式闪烁(出现微小的短闪光)。

仅添加 -webkit-transform:translateZ(0); (到容器!!!)确实有帮助。

.container {
    -webkit-transform: translateZ(0); /* <-- this */
}

.container section {
    -webkit-transform: translateZ(0) scale(.92); /* <-- and I added translate here as well */
    -webkit-transition: -webkit-transform .4s, opacity .3s;
    opacity:0;
}

.container.active section {
    -webkit-transform:translateZ(0) scale(1);
    -webkit-transition: -webkit-transform .3s, opacity .3s;
    opacity:1;
}

但说到过渡,还有以下部分代码:

.container {
    ...
    top:-5000px;
    left:-5000px;
    -webkit-transition: opacity .5s, top 0s .5s, left 0s 5s, width 0s 5s, height 0s 5s;
}
.container.active {
    -webkit-transition: opacity .5s;
    top:0;
    left:0;
    width:100%;
    height:100%;
}

考虑到,我想仅使用 css 切换来显示/隐藏弹出窗口(并且还要使其很好地消失,而不是仅使用“display:none”)。

所以,不知何故,在出现的 Safari 上(显然)继承了除了“不透明度”之外的过渡属性,即使我只用 -webkit-transition: opacity .5s; 重载了它们;

因此,添加以下内容解决了问题:

.container {
    ...
    -webkit-transition: opacity .5s, top 0s 0s, left 0s 0s, width 0s 0s, height 0s 0s;
}

There is no more relevant topic I've found for a problem I had, but that's related to mentioned above issue. So, might be helpful for some one.

In two words: I have some container (popup), some element inside.
Appearing goes the following way: container background is fading up to dark via opacity and element inside is scaling up (like coming closer to us from behind). Everything works great everywhere but not in Safari (Mac/Win/iPhone). Safari "initially" shows my container, but it blinks some strange way (tiny short flash appears).

Only adding -webkit-transform: translateZ(0); (to container!!!) did help.

.container {
    -webkit-transform: translateZ(0); /* <-- this */
}

.container section {
    -webkit-transform: translateZ(0) scale(.92); /* <-- and I added translate here as well */
    -webkit-transition: -webkit-transform .4s, opacity .3s;
    opacity:0;
}

.container.active section {
    -webkit-transform:translateZ(0) scale(1);
    -webkit-transition: -webkit-transform .3s, opacity .3s;
    opacity:1;
}

But speaking of the transitions, there was also the following part of code:

.container {
    ...
    top:-5000px;
    left:-5000px;
    -webkit-transition: opacity .5s, top 0s .5s, left 0s 5s, width 0s 5s, height 0s 5s;
}
.container.active {
    -webkit-transition: opacity .5s;
    top:0;
    left:0;
    width:100%;
    height:100%;
}

considering, that I want to show/hide the popup using only css switching (and also to make it disappear nicely instead just "display:none").

so, somehow on appearing Safari (obviously) was inheriting transition properties besides "opacity" even as I've overloaded them with only -webkit-transition: opacity .5s;

so, adding the following solved the problem:

.container {
    ...
    -webkit-transition: opacity .5s, top 0s 0s, left 0s 0s, width 0s 0s, height 0s 0s;
}
南薇 2024-12-20 07:39:14

我无法告诉你为什么要这样做,但 Safari 不会改变你的文本颜色,它会在过渡过程中以不同的方式对文本进行抗锯齿处理。文本边缘变得更平滑,文本本身也变得更细。如果您使用辅助工具放大小提琴,这一点会更加明显。在某些较小的尺寸下,表单文本旁边的按钮周围的阴影也会发生变化。 (Safari 是否有可能在过渡期间重绘某些内容,或者在子像素级别上重新调整它们的方向?请有人解释一下,它现在让我发疯!)

因为我也不知道为什么要这样做,这些可能不是最好的解决方案:

根据您要转换的内容,用 javascript 动画替换 css 转换可能会修复它。
例如,在您的小提琴中,比例转换也会出现问题,但类似的 jQuery 动画函数不会出现问题。

似乎有一些阴影和样式的抗锯齿变化不太明显(至少在小提琴中),因此您也可以尝试以不同的方式设置占位符和其他受影响文本的样式。
(如果您采用以下路线,此线程可能有助于设置占位符的样式: 使用 CSS 更改 HTML5 输入的占位符颜色 )

I can't begin to tell you why it's doing this, but Safari isn't changing your text color, it's anti-aliasing the text differently while the transition is in motion. The text edges get smoother, and the text itself becomes thinner. This is extra obvious if you zoom in on the fiddle with accessibility tools. At some smaller sizes, the shading around the button next to the form text shifts too. (Is it possible that Safari is redrawing some things, or reorienting them on a sub-pixel level during the transitions ? Somebody explain this please, it's driving me nuts now!)

Because I have no real idea why it's doing this either, these might not be the best solutions:

Depending on what you're transforming, replacing the css transform with a javascript animation will probably fix it.
For example in your fiddle, the problem also occurred with a scale transformation, but not with a similar jQuery animate function.

There seem to be some shades and styles where the anti-aliasing change is less obvious (at least in the fiddle), so you could also try styling the placeholders and other effected text differently.
(This thread may help with styling the placeholders, if you go that route: Change an HTML5 input's placeholder color with CSS )

本宫微胖 2024-12-20 07:39:14

感谢上面对抗锯齿的识别,以及下面文章的帮助,我修改了代码以包含 translate3d(0,0,0) 并且问题消失了:

    -webkit-transition-duration: .17s, .17s translate3d(0,0,0);

过渡不是和以前一样顺利,但这是另一个问题的主题。

使用 webkit 旋转时出现不稳定的文本抗锯齿-在 Chrome 中进行转换

http://johanbrook.com/design/css/a-fix-for-antialiasing-issues-in-webkit-browsers/

http://www.webkit.org/blog/386/3d-transforms/

Thanks to the identification of anti-aliasing above, as well as help from the articles below, I modified my code to include translate3d(0,0,0) and the problem disappeared:

    -webkit-transition-duration: .17s, .17s translate3d(0,0,0);

The transition isn't as smooth as it once was but that's a subject for another question.

Wonky text anti-aliasing when rotating with webkit-transform in Chrome

http://johanbrook.com/design/css/a-fix-for-antialiasing-issues-in-webkit-browsers/

http://www.webkit.org/blog/386/3d-transforms/

梦巷 2024-12-20 07:39:14

我遇到了同样的问题,在转换时一些文本变得抗锯齿。这种情况仅发生在锚文本中,这些锚文本相对于 e 与 z-index 定位在元素内部且与 z-index 本身一起定位。
如果我删除所有位置和索引,问题就会消失。

i had the same problem, while a transition some text became antialiased. this happen only in anchor text that are positioned relative e with z-index inside an element positioned and with z-index itself.
if i remove all position and index the problem disappear.

放血 2024-12-20 07:39:14

使用 transitiontranslate3d 也存在类似的问题。有时,页面上具有 :hover 样式的任何元素都会显示其悬停行为。我在使用滑块时遇到这个问题。将 -webkit-transform:translateZ(0); 放入 :hover 元素,其行为正常。

There is a similar problem using transition and translate3d. Sometimes any element on the page with :hover styles shows its hover behavior. I have this problem using a slider. Put the -webkit-transform: translateZ(0); to the :hover element and its behavior is normal.

临走之时 2024-12-20 07:39:14

对于rotation()也许没问题,但是对于scale()它不起作用-webkit-transform:translateZ(0);公式。

我用过:

-webkit-font-smoothing: antialiased;

For rotation() maybe it's fine, but for scale() It didn't worked the -webkit-transform: translateZ(0); formula.

I used :

-webkit-font-smoothing: antialiased;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文