-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
46 lines (34 loc) · 875 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
`dom-create-element`
var create = require('dom-create-element');
var el = create({
selector: 'div',
styles: 'preloader',
html: '<span>Text</span>'
});
*/
module.exports = create;
function create(opt) {
opt = opt || {};
var el = document.createElement(opt.selector);
if(opt.attr) for(var index in opt.attr)
opt.attr.hasOwnProperty(index) && el.setAttribute(index, opt.attr[index]);
"a" == opt.selector && opt.link && (
el.href = opt.link,
opt.target && el.setAttribute("target", opt.target)
);
"img" == opt.selector && opt.src && (
el.src = opt.src,
opt.lazyload && (
el.style.opacity = 0,
el.onload = function(){
el.style.opacity = 1;
}
)
);
opt.id && (el.id = opt.id);
opt.styles && (el.className = opt.styles);
opt.html && (el.innerHTML = opt.html);
opt.children && (el.appendChild(opt.children));
return el;
};