<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
createDiv(demo,500,500,null,null,'1px solid #f00',null,null);
function createDiv(id, px, sz, imgURL, position,
border, overflow, opacity) {
var dom = document.createElement('div');
if (imgURL) {
dom.style.backgroundImage = 'url(' + imgURL + ')';
}
//set generic properties
if (!id) {
id = createUniqueID("SuperMapDiv");
}
if (!position) {
position = "absolute";
}
modifyDOMElement(dom, id, px, sz, position,
border, overflow, opacity);
return dom;
};
function createUniqueID(prefix) {
if (prefix == null) {
prefix = "id_";
}
var num = 0;
num += 1;
return prefix + num;
};
function modifyDOMElement(element, id, px, sz, position,
border, overflow, opacity) {
if (id) {
element.id = id;
}
if (px) {
element.style.left = px.x + "px";
element.style.top = px.y + "px";
}
if (sz) {
element.style.width = sz.w + "px";
element.style.height = sz.h + "px";
}
if (position) {
element.style.position = position;
}
if (border) {
element.style.border = border;
}
if (overflow) {
element.style.overflow = overflow;
}
if (parseFloat(opacity) >= 0.0 && parseFloat(opacity) < 1.0) {
element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
element.style.opacity = opacity;
} else if (parseFloat(opacity) === 1.0) {
element.style.filter = '';
element.style.opacity = '';
}
};
</script>
创建元素
最新推荐文章于 2021-10-11 12:26:37 发布