1. Introduction
L'émergence de CSS3 rend les performances du navigateur plus colorées, et le plus grand impact sur la performance est l'animation. Lors de la rédaction d'animations dans la vie quotidienne, il est nécessaire de juger si le navigateur le soutient à l'avance, en particulier lors de l'écriture de la bibliothèque d'animation CSS3. Par exemple, l'état d'animation-play de la transition est pris en charge uniquement par certains navigateurs.
2. Méthode de test
La méthode suivante peut utiliser des scripts pour déterminer si le navigateur prend en charge un certain attribut CSS3:
/** * Determine whether the browser supports a certain CSS3 attribute* @param {String} Property name* @return {Boolean} true/false * @version 1.0 * @author ydr.me * April 4, 2014 14:47:19 */ function supportCss3(style) { var prefix = ['webkit', 'Moz', 'ms', 'o'], i, HumpString = [], htmlstyle = document.DocumentElement.style, _toHumb = function (string) {return String.replace (/ - (/ w) / g, function (0 0, $ 1) {return 1 1.ToupperCase ();}); }; pour (i en préfixe) HumpString.push (_toHumb (préfixe [i] + '-' + style)); HumpString.push (_toHumb (style)); for (i in humpstring) if (HumpString [i] in htmlstyle) renvoie true; retourne false; }3. Comment utiliser
alert (supportcss3 ('animation-play-state'));