IE 10 + 11:使用calc()的CSS转换不起作用 [英] IE 10 + 11: CSS transitions with calc() do not work

查看:1856
本文介绍了IE 10 + 11:使用calc()的CSS转换不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过CSS过渡从右到左为鼠标移动设置动画。这适用于除Internet Explorer之外的所有浏览器。原因是我在CSS left属性中使用(并且需要使用)calc()。

I am animating a container on mouseover from right to the left with CSS transitions. This works fine in all browsers except Internet Explorer. The reason is that I am using (and need to use) calc() in my CSS left property.

我在这里创建了一个现场演示:现场演示

I created a live demo here: Live Demo

CSS如下所示:

div {
    background: red;
    width: 100px;
    height: 100px;
    position: absolute;
    top: 100px;
    left: 90%;
    -webkit-transition: left 0.7s cubic-bezier(0.77, 0, 0.175, 1);
    -moz-transition: left 0.7s cubic-bezier(0.77, 0, 0.175, 1);
    -o-transition: left 0.7s cubic-bezier(0.77, 0, 0.175, 1);
    transition: left 0.7s cubic-bezier(0.77, 0, 0.175, 1);
}
div.translate-less {
    left: calc(90% - 4rem)
}

我在使用jQuery鼠标悬停时添加了.translate-less类:

I am adding the class .translate-less on mouseover with jQuery:

$(document)
.on( 'mouseenter', 'div', function(){
    $(this).addClass('translate-less')
})
.on( 'mouseleave', 'div', function(){
    $('div').removeClass('translate-less');
})

现在我想在Internet Explorer中顺利过渡。为此,我甚至会抛弃这些特定浏览器的calc()并添加一个规则,如 left:85%; 。但是IE 10和11已经放弃对条件评​​论的支持并且似乎无法专门针对这些浏览器。 IE 10可以通过 -ms-high-contrast-hack 进行定位,但是IE 11不能。我不想使用JavaScript 来检测浏览器,因为这似乎比使用CSS黑客。

Now I would like to have a smooth transition in Internet Explorer. For that, I would even ditch the calc() for these specific browsers and add a rule like left: 85%;. But IE 10 and 11 have dropped support for conditional comments and there seems to be no way to target these browsers specifically. IE 10 can be targeted with the -ms-high-contrast-hack, but IE 11 cannot. I do not want to use JavaScript to detect the browser because this seems even hackier than using CSS hacks.

任何帮助?提前致谢!

推荐答案

也许转换:translateX()可以提供解决方法。根据具体情况,使用转换和正确的属性可能会更好:

Maybe transform: translateX() can provide a work-around. Depending on the circumstances, using transforms and the right property might be better:

right: 10%;
transform: translateX(-4rem); 

以下是您脚本的修改版本:http://jsfiddle.net/xV84Z/1/

Here is a modified version of your script: http://jsfiddle.net/xV84Z/1/.

或者,虽然你不能使用<$ c IE中的$ c> calc()在 translateX()内(因为一个bug ),你可以应用多个 translateX() s in a transform:

Alternatively, while you can't use calc() within a translateX() in IE (because of a bug), you can apply multiple translateX()s in a transform:

/* This */
transform: translateX(90%) translateX(-4rem);
/* is equivalent to this */
transform: translateX(calc(90% - 4rem));

(但是,在这种情况下,90%意味着目标的90%,而不是父目标。)

(However, 90% in this case means 90% of the target, not the parent.)

这篇关于IE 10 + 11:使用calc()的CSS转换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆