【问题标题】:Code not working in IE and Edge代码在 IE 和 Edge 中不起作用
【发布时间】:2016-07-01 06:05:14
【问题描述】:

我有一个在 Chrome 中完美运行的脚本,但 CSS 在 Edge 中不起作用,滚动文本在 IE10 中不起作用。

看看它在 Chrome 中应该如何工作(请等待大约 5 秒让滚动文本开始:

https://jsfiddle.net/oxw4e5yh/

CSS:

<style>
/* Make it a marquee */

.marquee {
    width: 100%;
    left: 0px;
    height: 10%;
    position: fixed;
    margin: 0 auto;
    white-space: nowrap;
    overflow: hidden;
    background-color: #000000;
    bottom: 0px;
    color: white;
    font: 50px'Verdana';
}
.marquee span {
    display: inline-block;
    padding-left: 100%;
    text-indent: 0;
    animation: marquee linear infinite;
    background-color: #000000;
    color: white;
    bottom: 0px;
}
/* Make it move */

@keyframes marquee {
    0% {
        transform: translate(10%, 0);
    }
    100% {
        transform: translate(-100%, 0);
    }
}
/* Make it pretty */

.scroll {
    padding-left: 1.5em;
    position: fixed;
    font: 50px'Verdana';
    bottom: 0px;
    color: white;
    left: 0px;
    height: 10%;
}
</style>

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    您的 CSS 在 Edge 中不起作用的原因是 font 声明。缺少一个空格。改内部.marquee

    font: 50px Verdana;
    

    它在 IE10/IE11 中不起作用的原因是 animationDuration 属性在 JavaScript 中不受支持。见here

    如果你想让它工作,你应该从css中删除animation: marquee linear infite;并将其添加到JavaScript

    CSS

    .marquee span {
        display: inline-block;
        padding-left: 100%;
        text-indent: 0;
        background-color: #000000;
        color: white;
        bottom: 0px;
    }
    

    JS

    spanSelector[i].style.animation = "marquee linear infinite " + timeTaken + "s";
    

    现在它应该可以在 IE10/IE11 中运行 :)

    【讨论】:

    • 我在..marquee 中更改了font,它在Edge 中有效,但在IE 中无效。谢谢
    • 是的,我很抱歉。里面.marguee。在 IE10/IE11 中,不支持使用 JavaScript 更改元素的 animationDuration
    • @Wienievra 更新答案
    • 所以我将spanSelector[i].style.animationDuration = timeTaken + "s"; 替换为spanSelector[i].style.animation = "marquee linear infinite " + timeTaken + "s";?
    • @Wienievra 完全正确 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 2018-11-19
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    相关资源
    最近更新 更多