setMask的实现

// 给任意dom设置一个蒙层,并使蒙层区域不可点击
function showmask(dom) {
    var domRect = dom.getBoundingClientRect(),
        domTop = domRect.top + window.pageYOffset,
        domLeft = domRect.left + window.pageXOffset;

    var maskDiv = document.createElement("div");

    maskDiv.style.width = domRect.width + "px";
    maskDiv.style.height = domRect.height + "px";
    maskDiv.style.top = domTop + "px";
    maskDiv.style.left = domLeft + "px";
    maskDiv.style.background = "#000";
    maskDiv.style.opacity = "0.5";
    maskDiv.style.position = "absolute";
    maskDiv.style.zIndex = 999;

    document.body.appendChild(maskDiv);
}

你可能感兴趣的:(前端基础)