Skip to content

Instantly share code, notes, and snippets.

@QETHAN
Created April 28, 2013 04:52
Show Gist options
  • Save QETHAN/5475936 to your computer and use it in GitHub Desktop.
Save QETHAN/5475936 to your computer and use it in GitHub Desktop.
创建元素 SeaJS
/**
* 创建元素
*/
define(function(require, exports) {
exports.create = function(tagName, attr) {
var element = null;
if (typeof tagName === "string") {
element = document.createElement(tagName);
if (typeof attr === "object") {
var keyAttr, keyStyle;
for (keyAttr in attr) {
if (keyAttr === "styles" && typeof attr[keyAttr] === "object") {
// 样式们
for (keyStyle in attr[keyAttr]) {
element.style[keyStyle] = attr[keyAttr][keyStyle];
if (keyStyle === "opacity" && window.innerWidth + "" == "undefined") {
element.style.filter = "alpha(opacity="+ (attr[keyAttr][keyStyle] * 100) +")";
}
}
} else {
if (keyAttr === "class") {
keyAttr = "className";
}
element[keyAttr] = attr[keyAttr];
}
}
}
}
return element;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment