arayts
Version:
让 TypeScript 开发如丝般顺滑。ArayTS 提供了一套高效、优雅的算法工具集,包含常用的数据结构与算法实现,帮助开发者轻松构建可靠的应用程序。
35 lines (34 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var applyStyles = function (element) {
var prefixedStyles = {};
// Iterate through the style properties of the element
for (var property in element.style) {
if (Object.hasOwnProperty.call(element.style, property)) {
var prefixedProperty = addVendorPrefix(property);
prefixedStyles[prefixedProperty] = element.style[property];
}
}
// Apply the styles back to the element
Object.assign(element.style, prefixedStyles);
};
var addVendorPrefix = function (property) {
var prefixes = ['', 'webkit', 'moz', 'ms', 'o'];
var style = document.createElement('div').style;
// Check if the property is supported without prefixes
if (property in style) {
return property;
}
// Add prefixes and check if any is supported
for (var _i = 0, prefixes_1 = prefixes; _i < prefixes_1.length; _i++) {
var prefix = prefixes_1[_i];
var prefixedProperty = prefix + (prefix ? property.charAt(0).toUpperCase() + property.slice(1) : property);
if (prefixedProperty in style) {
return prefixedProperty;
}
}
// If no prefix is supported, return the original property
return property;
};
exports.default = applyStyles;
// Example usage