const loading: any = {
ele: null,
render() {
var fragment = document.createDocumentFragment();
const div = document.createElement("div");
div.style.position = "fixed";
div.style.top = "0";
div.style.left = "0";
div.style.right = "0";
div.style.bottom = "0";
div.style.zIndex = "100";
div.style.backgroundColor = "rgba(0,0,0,.5)";
const img = document.createElement("div");
img.style.width = "100px";
img.style.height = "100px";
img.style.position = "absolute";
img.style.top = "50%";
img.style.left = "50%";
img.style.transform = "translate(-50%,-50%)";
img.style.backgroundImage = `url(${require("../../assets/images/index.svg")})`;// loading图片的url
img.style.backgroundPosition = "center center";
img.style.backgroundSize = "100% 100%";
div.appendChild(img);
fragment.appendChild(div);
this.ele = div;
document.body.appendChild(fragment);
},
open() {
if (!this.ele) {
this.render();
}
},
close() {
if (this.ele) {
document.body.removeChild(this.ele);
this.ele = null;
}
}
};
export { loading };
简单实现一个函数调用loading图
最新推荐文章于 2023-08-31 08:57:13 发布