点击按钮或者文字弹出div 块

JQuery弹出层,点击按钮后弹出遮罩层,还有关闭按钮

 




jQuery弹出层效果













关闭

目前来说,我还是喜欢这个自己改造的弹出层。自己在项目中也用的是这个。


 

 

 

window.onload = function (){
    var myDiv = document.getElementById("MyDiv");
    var move = document.getElementById("move");
    var bDrag = false;
    var disX = disY = 0;
    
    move.onmousedown = function (event){
        var event = event || window.event;
        bDrag = true;
        disX = event.clientX - myDiv.offsetLeft;
        disY = event.clientY - myDiv.offsetTop;
        this.setCapture && this.setCapture();
        return false;
    };
    document.onmousemove = function (event){
        if (!bDrag) return;
        var event = event || window.event;
        var iL = event.clientX - disX;
        var iT = event.clientY - disY;
        var maxL = document.documentElement.clientWidth - myDiv.offsetWidth;
        var maxT = document.documentElement.clientHeight - myDiv.offsetHeight;
        iL = iL < 0 ? 0 : iL;
        iL = iL > maxL ? maxL : iL;
        iT = iT < 0 ? 0 : iT;
        iT = iT > maxT ? maxT : iT;
        myDiv.style.marginTop = myDiv.style.marginLeft = 0;
        myDiv.style.left = iL + "px";
        myDiv.style.top = iT + "px";
        return false;
    };
    document.onmouseup = window.onblur = move.onlosecapture = function (){
        bDrag = false;
        move.releaseCapture && move.releaseCapture();
    };
}

你可能感兴趣的:(前端知识)