使用js获取到css3的兼容前缀

阅读 34

2023-01-30


将下面的代码放入到js当中

function prefix() {
var div = document.createElement('div');
var cssText = '-webkit-transition:all .1s; -moz-transition:all .1s; -o-transition:all .1s; -ms-transition:all .1s; transition:all .1s;';
div.style.cssText = cssText;
var style = div.style;
if (style.webkitTransition) {
return '-webkit-';
}
if (style.MozTransition) {
return '-moz-';
}
if (style.oTransition) {
return '-o-';
}
if (style.msTransition) {
return '-ms-';
}
return '';
}


在需要的地方,或者赋值给变量使用

var cssPrefix = prefix();
alert(cssPrefix);




精彩评论(0)

0 0 举报