注意,不拿用户代理switching
考虑
/chrome|chromium|firefox|msie|opera/.exec(navigator.userAgent.toLowerCase()).toString().replace(/chrome|chromium/g, "-webkit-").replace(/firefox/g, "-moz-").replace(/msie/g, "-ms-").replace(/opera/g, "-o-")
下面js
检查浏览器style
属性实际上支持已存在的style
属性,或者稍后动态插入。它主要为animations
组成,虽然可以修改为在浏览器中测试任何css
,style
属性。如果props
已经存在于stylesheet
,vendor prefixes
被插入stylesheet
。如果props
稍后动态插入,vendor prefixes
也被插入,或附着在那些props
的功能
// prefix.1.1.min.js 2013, 2014 guest271314
// add css `prefixes`
// TODO: `opera` compatibility; utilizes `-o-`, `-webkit-`, w3c
(function prefix() {
/* var el = $(selector).get(0), i.e.g, $("body").get(0), $("#animated").get(0) */
var prefixes = {"MozAnimation": "-moz-","webkitAnimation": "-webkit-"
,"msAnimation": "-ms-","oAnimation": "-o-"};
var props = ["animation", "backface-visibility", "border-radius"
, "box-shadow", "transform", "transform-style", "transition"];
$.each(prefixes, function(key, val) {
$("style")
.attr({"data-prefix": val,"class": String(val).replace(/-/g, "")});
return !(key in el.style);
});
$.each(props, function(index, value) {
var cssPrefix = $("style").attr("data-prefix");
if (value in el.style === false) {
$.fn.pfx = function(prop, pfxprop, q) {
return $("style").html($("style").text()
.replace(new RegExp(prop, "g"), q
+ $("style").attr("data-prefix") + pfxprop))
};
$("style").pfx("@keyframes", "keyframes", "@")
.pfx(value, value, "");
};
});
}());
github上https://github.com/guest271314/prefix/blob/master/prefix.1.1.min.js
http://api.jquery.com/jquery.browser/ – David
关于你的评论“我需要这个使用jQuery。我最初的选择是js“请注意,jQuery **是** javascript,它只是一个JavaScript库。 – mralexlau
也为了您的观点,修改浏览器的用户代理,是的,这是可能的,但可能不是你想要关注的东西。 imo,如果用户故意更改其用户代理字符串,那么他们应该期望在网站上看到不同的风格行为。 – mralexlau