【问题标题】:animate color web icon font doesn't work on IE 8动画彩色 web 图标字体在 IE 8 上不起作用
【发布时间】:2013-05-27 09:02:39
【问题描述】:

我对这个问题感到困惑。 我想动画图标字体的颜色,它在所有现代浏览器中都可以正常工作,但在 IE 8 中不行!

我们有一个链接:

<a id="newsletter_subbut"><i class="icon-web-mail"></i></a>

这是我的 CSS 代码:

#newsletter_subbut {
    border: none;
    height: 30px;
    width:40px;
    margin-left: -8px;
    font-size:22px;
    position:absolute;
    display:inline-block;
    padding-top:9px;
    bottom:0px;
    z-index: 1;
}
.icon-web-mail:before {
    font-family: 'batch';
    speak: none;
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    content: "\F14C";
}

这是我的 jQuery 代码:

$('#newsletter_subbut').find("i").stop().animate({color: "#fa2a18"},'slow');

【问题讨论】:

标签: jquery html css jquery-animate


【解决方案1】:

IE8 无法为颜色设置动画,因为浏览器无法自行为颜色设置动画。您需要一个可以为 IE8 工作的脚本。

@Hadi 添加了自定义颜色动画脚本,小巧轻便。

我更喜欢 Jquery UI,因为它会为您解决问题。它已添加到我的 jsfiddle 中。 (参见框架和扩展)。 http://jsfiddle.net/brutusmaximus/667kF/6/

$('#newsletter_subbut').find("i").stop().animate({color: "#fa2a18"},'slow');

更新:您正在添加带有

的图标
i:before { content: \F14C"; }

Jquery 正在为内容的实际 i 设置动画 :before。但是谷歌搜索似乎还不支持动画伪类。

http://css-tricks.com/transitions-and-animations-on-css-generated-content/

有一个解决方案,但只适用于现代浏览器。

您的解决方案是在 html 中添加 unicode。见我的http://jsfiddle.net/brutusmaximus/667kF/8/

【讨论】:

  • 我们的答案对您有用吗?你能为我们的答案投票吗?谢谢!
  • 很遗憾没有!但是谢谢。正如我所说,这个问题出在图标网络字体上。它适用于普通文本
  • PLING!当然,它不起作用。有关说明,请参阅帖子更新。
【解决方案2】:

我不知道您使用的是哪个版本的 jquery。无论如何,动画颜色不适用于 1.9.1,可能在早期版本中有效。有时 IE8 不理解 animate 属性。你可以这样试试——

$('#newsletter_subbut').find("i").stop().animate({color: "#fa2a18"}, 1000, function(){ $('#newsletter_subbut').find("i").animate({ color: "#fa2a18" }); });

或

$('#newsletter_subbut').find("i").animate({ color: "#000" }); // your original color
$('#newsletter_subbut').find("i").animate({ color: "#fa2a18" });

我知道这很疯狂。但它对我有用。

如果您使用的是 jquery 1.9.x,那么 - 试试这个小提琴 - http://jsfiddle.net/HETuE/ - 它也适用于 ie8

【讨论】:

  • thx 伙计,我使用 jquery 1.9.1 和这个插件 bitstorm.org/jquery/color-animation 即使在 ie8 中它也能很好地工作,但是当我使用普通文本而不是图标 web 字体时
  • 你能把它摆弄一下吗,因为我可以现场看到它?
  • 嗨伙计们,我搜索了更多,不幸的是发现 IE 8 不支持 :before 和 :after 内容的过渡和动画颜色。非常感谢您的回复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-26
  • 2014-01-02
  • 2014-11-02
  • 1970-01-01
  • 2016-01-30
相关资源
最近更新 更多