zoukankan      html  css  js  c++  java
  • js动态加载的蒙板弹框

    我们访问一些网站时总会遇到这种点击后,背景像被打上一层模板一样,这个是怎么做到的呢?

    它是将这个弹框div独立于页面容器wrap,设置position为absolute,将其水平垂直之后都居中,设置弹框div不显示,点击页面的登录按钮时,弹框div显示,并将页面容器的opacity设置0.5,下面的代码是完全动态加载的蒙板弹框。

       window.onload = function(){
                Wrap = document.createElement("div")
                Wrap.style.height =  window.innerHeight+'px'
                Wrap.style.background='#06f'
                Wrap.innerHTML='<button id="button" onclick="ButtonClick()">确认</button>'
                document.body.appendChild(Wrap)
    
                Odiv = document.createElement("div")
                Odiv.style.border = "1px #ababab solid"
                Odiv.style.background = '#39f'
                Odiv.style.height = 200+'px'
                Odiv.style.width = 300+'px'
                Odiv.style.position = 'absolute'
                Odiv.style.top = '50%'
                Odiv.style.marginTop = -100 + 'px'
                Odiv.style.left = '50%'
                Odiv.style.borderRadius=5+'px'
                Odiv.style.marginLeft = -150+'px'
                Odiv.style.color = '#333'
                Odiv.style.index = 3
    
                document.body.appendChild(Odiv)
    
                Otitle = document.createElement('div')
                Left = document.createElement('div')
                ClearFixed = document.createElement('div')
                Right =  document.createElement('button')
                Left.innerHTML = '头部'
                Right.innerHTML = 'X'
                Right.setAttribute('id','Cancel')
                Left.style.float='left'
                Right.style.float = 'right'
                ClearFixed.style.clear = 'both'
                Otitle.appendChild(Left)
                Otitle.appendChild(Right)
                Otitle.appendChild(ClearFixed)
                Ocontent = document.createElement('div')
                Ocontent.innerHTML='显示内容'
                Otitle.style.padding = 10+'px'
                Otitle.style.borderBottom = '1px #ababab solid '
                Ocontent.style.padding = 10+'px'
                Odiv.appendChild(Otitle)
                Odiv.appendChild(Ocontent)
                Odiv.style.display = 'none'
            }
            function ButtonClick(){
                Odiv.style.display = 'block'
                Wrap.style.background='#ccc'
                Wrap.style.opacity='0.2'
    
                Cencel = document.getElementById('Cancel')
                Cencel.onclick = function(){
                    Odiv.style.display = 'none'
                    Wrap.style.background='#06f'
                    Wrap.style.opacity='1'
                }
            }
    

      

  • 相关阅读:
    Sharding-JDBC(三)3.1.0版本实践
    Sharding-JDBC(二)2.0.3版本实践
    Sharding-JDBC(一)简介
    Java并发(六)线程池监控
    Java并发(五)线程池使用番外-分析RejectedExecutionException异常
    Java并发(四)线程池使用
    Java并发(三)线程池原理
    Java并发(二)异步转同步
    tarjan+概率
    线段树(种树)
  • 原文地址:https://www.cnblogs.com/xiabaoying/p/6516763.html
Copyright © 2011-2022 走看看