简体   繁体   English

使用IE 10进行CSS转换

[英]CSS transition with IE 10

so I have this small CSS transition that works pretty good in both Firefox and Chrome (latest builds). 所以我有一个小的CSS过渡,在Firefox和Chrome(最新版本)中都很好用。 However it looks like garbage in IE 10 (doesn't render properly). 然而,它看起来像IE 10中的垃圾(无法正确渲染)。 I am wondering if there is some hack to have it appears as it does in other browsers. 我想知道是否有一些黑客让它出现在其他浏览器中。

Here is the link to a pen on codepen (look in IE 10). 这是在codepen上的的链接(在IE 10中查看)。 Works great in Chrome or Firefox. 适用于Chrome或Firefox。

I included all the code here as I know some people hate when it's not in the question. 我在这里包含了所有代码,因为我知道有些人讨厌它不在问题中。 but is all viewable in the pen. 但是笔中都可以看到。 Any way insight onto how I fix this would be awesome. 任何方式洞察我如何解决这个将是非常棒的。

CSS: CSS:

#menu-icon {
    border-radius: 0.2em;
    display: block;
    color: white;
    font-size: 4em;
    font-weight: 900;
    width: 1.5em;
    background: grey;
    letter-spacing: -0.17em;
    line-height: 0.4em;
    position: absolute;
    bottom: 8em;
    left: 4em;
    height: 1.4em;
    text-align: center;
    padding: 0 !important;
    margin: 0 !important;
    cursor: pointer;
}

#menu-icon span {
    display: inline-block;
    padding: 0px;
    margin: 0px;
}

.menu-bar {
    top: -0.4em;
    position: relative;
    width: 90%;
    margin-left: 0%;
    margin-right: 10%;
}

.menu .bar-left {
            transition:         transform 0.5s;
    -webkit-transition: -webkit-transform 0.5s;
}

.menu .bar-right {
            transition:         transform 0.5s;
    -webkit-transition: -webkit-transform 0.5s;
}

.arrow .bar-left {
    height: 0.3em;

    -webkit-transform: translate(0.34em, 0.05em) rotate(35deg);
       -moz-transform: translate(0.34em, 0.05em) rotate(35deg);
            transform: translate(0.34em, 0.05em) rotate(35deg);

            transition:         transform 0.5s;
    -webkit-transition: -webkit-transform 0.5s;

            transform-origin: center center;
    -webkit-transform-origin: center center;
}

.arrow .bar-right {
    height: 0.3em;
    -webkit-transform: translate(-0.34em, 0.15em) rotate(-35deg);
       -moz-transform: translate(-0.34em, 0.15em) rotate(-35deg);
            transform: translate(-0.34em, 0.15em) rotate(-35deg);

            transition:         transform 0.5s;
    -webkit-transition: -webkit-transform 0.5s;

            transform-origin: center center;
    -webkit-transform-origin: center center;
}

HTML: HTML:

<div id="menu-icon" >
    <div class="menu-bar">
        <span class="bar-left ">_</span>
        <span class="bar-right ">_</span>
    </div>
    <div class="menu-bar">
        <span class="bar-left ">_</span>
        <span class="bar-right ">_</span>
    </div>
    <div class="menu-bar">
        <span class="bar-left ">_</span>
        <span class="bar-right ">_</span>
    </div>
</div>

JS: JS:

function init() {
    var menu = document.getElementById("menu-icon");
    if(menu.addEventListener) {
        menu.addEventListener("click", function() { 
            if(menu.className=="arrow") {
                menu.className = "menu";
            } else {
                menu.className = "arrow";
            }
        }, false);
    } else if(menu.attachEvent) {
        menu.attachEvent("onclick", function() {
            if(menu.className=="arrow"){
                menu.className = "menu";
            }else{
                menu.className = "arrow";
            }
        });
    }
};
if(window.addEventListener) {
    window.addEventListener("load", init, false);
} else if(window.attachEvent) {
    window.attachEvent("onload", init);
} else {
    document.addEventListener("load", init, false);
}

This is not so much an answer as to 'why' this happens, simply a way to deal with it... The true answer to that question is simply just that Internet Explorer is terrible. 这不是“为什么”这种情况发生的答案,只是一种处理它的方法......这个问题的真正答案只是Internet Explorer很糟糕。

Instead, just as a little workaround, IE seems to handle animations on other elements better than it does on text. 相反,就像一个小的解决方法,IE似乎更好地处理其他元素上的动画,而不是文本。 So, my suggestion would be to take out the underscores in your spans, and just style the span elements to look the same. 因此,我的建议是在您的跨度中取出下划线,并将span元素的样式设置为相同。 I've made a modified version of your pen to show this in use (code might be a bit messy as I just kind of hacked it from what you had to this, so keep in mind that there is room for improvement there) 我已经修改了你的笔,以显示它的使用情况(代码可能有点乱,因为我只是从你所拥有的东西中砍掉它,所以请记住,那里有改进的余地)

http://codepen.io/anon/pen/DGnwt http://codepen.io/anon/pen/DGnwt

Use the vendor prefix: 使用供应商前缀:

-ms-

Example: 例:

-ms-transform: translate(0.34em, 0.05em) rotate(35deg);

Here you can find out more about vendor prefixes: http://webdesign.about.com/od/css/a/css-vendor-prefixes.htm 在这里,您可以找到有关供应商前缀的更多信息: http//webdesign.about.com/od/css/a/css-vendor-prefixes.htm

But an even better solution, remove all the prefixes in your CSS. 但是更好的解决方案是删除CSS中的所有前缀。 Example, only use this: 例如,只使用这个:

transform: translate(0.34em, 0.05em) rotate(35deg);

Then go to this page, http://modernizr.com/ Click on Production and check all the features you have used and it will add the necessary lines of CSS with prefixes for you in order to support multiple browsers. 然后转到此页面, http://modernizr.com/单击生产并检查您使用的所有功能,它将为您添加必要的带有前缀的CSS行,以支持多个浏览器。 Download it. 下载它。 Put it in 把它放进去

<head></head>

like a Javascript file. 像一个Javascript文件。

You could also use this: http://leaverou.github.io/prefixfree/ 你也可以使用这个: http//leaverou.github.io/prefixfree/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM