页面添加遮罩层:
function mask() {
var mask = document.createElement('div');
var innerWidth =window.innerWidth;
var innerHeight =window.innerHeight;
mask.id = 'maskDiv';
mask.style.width = innerWidth+'px';
mask.style.height = innerWidth+'px';
mask.style.background = '#000000';
mask.style.opacity = '0.2';
mask.style.position = 'absolute';
mask.style.display = 'block'; // 取消遮罩 设置为 none
mask.style.top = 0+'px';
mask.style.zIndex = 999; // 设置元素层级
document.body.appendChild(mask);
var img = document.createElement('img');
//遮罩层添加动图
img.setAttribute("id", "newImg");
img.src='loading.gif';
img.style.width='25px';
img.style.height='25px';
img.style.marginLeft=(innerWidth - 25)/2 +'px';
img.style.marginTop=(innerHeight - 25)/2+'px';
mask.appendChild(img);
}
function removeMask() {
document.getElementById("maskDiv").remove();
}