简体   繁体   English

缺少CSS3支持时,如何轻松翻转CSS卡翻转效果?

[英]How can this CSS card flip effect fall back gracefully when CSS3 support is lacking?

I'm using the library FlipClock.js to build an analog-style clock that uses a version of the CSS "card flip effect." 我正在使用FlipClock.js库来构建一个模拟样式的时钟,该时钟使用CSS版本的“卡片翻转效果”。 Unfortunately, only after building out my project did I notice a long-standing bug affecting Internet Explorer 9 and below: 不幸的是,只有在构建了我的项目之后,我才注意到一个影响Internet Explorer 9及以下版本的长期存在的错误:

https://github.com/objectivehtml/FlipClock/issues/7 https://github.com/objectivehtml/FlipClock/issues/7

In IE9 and below, the clock time lags by one second (ie, in the first second of animation, nothing visible changes), and the digits in the clock are also offset by a value of 1. My expectation is not for the CSS flip animation to work, but for the digits to change instantly as they currently do, only be correct. 在IE9及以下版本中,时钟时间滞后一秒(即在动画的第一秒中,没有可见的变化),并且时钟中的数字也偏移了值1。我的期望不是CSS翻转动画可以正常工作,但要使数字像当前一样立即更改,只能正确。

I've been troubleshooting for a while but have yet to find a solution or even pinpoint the problem. 我已经进行了一段时间的故障排除,但尚未找到解决方案,甚至无法找到问题所在。 I have a hunch that this isn't a script-related bug; 我有一个预感,这不是脚本相关的错误; I suspect that the digits are changing correctly in the HTML (hard to verify with IE's developer tools), but that they're just not showing as intended due to one or more CSS rules that were written not considering IE9's poor CSS3 support. 我怀疑这些数字在HTML中正确更改了(很难用IE的开发人员工具进行验证),但是由于编写的一个或多个CSS规则没有考虑到IE9对CSS3的不良支持,因此它们并未按预期显示。 I'm kind of expecting (or at least hoping) to stumble upon a CSS property or two that just fixes it. 我有点期待(或至少希望)偶然发现一个或两个CSS属性,仅对其进行修复。

The library is based on a proof-of-concept, which exhibits the same problem: 该库基于概念证明,它也存在相同的问题:

http://codepen.io/ademilter/pen/czIGo http://codepen.io/ademilter/pen/czIGo

I'm troubleshooting there to keep it simple, and if I find a fix, will submit a pull request to the FlipClock.js library. 我正在那里进行故障排除,以使其保持简单,如果找到修复程序,它将向FlipClock.js库提交拉取请求。

I would greatly appreciate any help! 我将不胜感激任何帮助!

After removing the CSS animations and shadows, changing the z-index of li.before might do the trick (see http://codepen.io/cbuckley/pen/rysja ): 删除CSS动画和阴影后,更改li.beforez-index可能会达到目的(请参阅http://codepen.io/cbuckley/pen/rysja ):

body.play ul li.before {
    z-index: 1;  /* was previously 3 */
}

So you could use z-index: 1 by default, then feature-detect for CSS animations in the JavaScript and add a body class (say body.supports-animation ). 因此,您可以默认使用z-index: 1 ,然后在JavaScript中对CSS动画进行特征检测,并添加一个body类(例如body.supports-animation )。 Then the relevant CSS might look like: 然后相关的CSS可能如下所示:

body.play ul li.before {
    z-index: 1;
}

body.play.supports-animation ul li.before {
    z-index: 3;
}

/* Prefix animation/background declarations with body.supports-animation too */

Caveat: I haven't tried this with FlipClock, nor have I actually tested on a browser without animation support, but I hope it gives one possible option :-) 警告:我没有用FlipClock尝试过,也没有在没有动画支持的浏览器上进行过测试,但是我希望它提供一个可能的选择:-)

Just changing the z-index will fix the problem for IE8 and IE9 but will break the transition for all modern browsers. 只需更改z-index即可解决IE8和IE9的问题,但会中断所有现代浏览器的过渡。

To Target specifically I8 or IE9 you can use this: On your JS file add: 要专门针对I8或IE9,可以使用以下方法:在JS文件中添加:

var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);

then on your css you can detect IE8 and IE9 with this code (flipclock.css line 160): 然后在CSS上,您可以使用以下代码检测IE8和IE9(flipclock.css第160行):

/* PLAY */
.flip-clock-wrapper ul.play li.flip-clock-before {
    z-index: 3;/*Original */
}
/*ie8 and ie9 fixes*/
html[data-useragent*='MSIE 8.0'] .flip-clock-wrapper ul.play li.flip-clock-before {
    z-index: 1;
}

html[data-useragent*='MSIE 9.0'] .flip-clock-wrapper ul.play li.flip-clock-before {
    z-index: 1;
}

That fixed the problem for me! 那为我解决了问题!

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

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