移动端实现遮罩对话框

7 篇文章 0 订阅

实现原理:

 点击某一控件实现遮罩弹出会话框 原理就是点击后弹出两个div样式 。其中一个就是遮罩层  给他添加透明度即可实现遮罩,另一个就是对话框内容

 

<div class="mask" id="mask"></div>
			<div class="input_informatino" id="input_informatino">
				<div class="information_title">
					<span>身份验证</span>
					<i class="iconfont icon-cha" id="close"></i>
				</div>
				<div class="information_content">
					<ul>
						<li>
							<i class="iconfont icon-shoujihao"></i>
							<input type="number" name="" placeholder="请输入手机号">
						</li>
						<li>
							<i class="iconfont icon-yanzhengma"></i>
							<input type="number" name="" class="msmcode" id="msmcode" placeholder="输入验证码">
							<span>获取验证码</span>
						</li>
					</ul>
					<button>提交</button>
				</div>
			</div>

 

<script type="text/javascript">
        $("#immediately").click(function(){
            $("#mask").show();
            $("#input_informatino").show();//查找ID为popup的DIV show()显示#gray
            $("body").css("overflow","hidden");
            showMask();
            letDivCenter(".input_informatino");
        });
        //兼容火狐、IE8
        function showMask(){
            $("#mask").css("height",$(document).height());
            $("#mask").css("width",$(document).width());
            $("#mask").show();
        }

        //让指定的DIV始终显示在屏幕正中间
        function letDivCenter(divName){ 
            var top = ($(window).height() - $(divName).height())/2; 
            var left = ($(window).width() - $(divName).width())/2; 
            var scrollTop = $(document).scrollTop(); 
            var scrollLeft = $(document).scrollLeft(); 
            $(divName).css( { position : 'absolute', 'top' : top + scrollTop, left : left + scrollLeft } ).show();
        }

        $("#close").click(function(){
            $("#mask").hide();
            $("#input_informatino").hide();
        })
    </script>

 

.mask{
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: absolute;
    top: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
    display: none;
}

.input_informatino{
    width: 80%;
    height: auto;
    position: absolute;
    top: 25%;
    left: 10%;
    z-index: 100;
    display: none;
    padding: 0px 10px;
    background-color: #ffffff;
}
.information_title{
    width: 100%;
    height: 50px;
    line-height: 50px;
}
.information_title span{
    font-size: 15px;
    color: #212121;
}
.information_title i{
    float: right;
}
.information_content ul li{
    width: 100%;
    height: 55px;
    position: relative;
    line-height: 55px;
    margin-top: 5px;
    float: left;
    border: thin solid #e0e0e0;
}
.information_content ul li i{
    width: 10%;
    float: left;
    text-align: right;
    font-size: 20px;
}
.information_content ul li input{
    width: 90%;
    height: 50px;
    font-size: 13px;
    line-height: 50px;
    float: left;
    color: #adadad;
    border: none;
}
.information_content ul li span{
    position: absolute;
    top: 0;
    right: 10px;
    color: #6591e0;
    font-size: 13px;
    border-left: thin solid #e0e0e0;
    padding-left: 10px;
}
.msmcode{
    width: 50%;

}
.information_content button{
    width: 100%;
    background-color: #6591e0;
    height: 40px;
    line-height: 40px;
    color: #ffffff;
    margin-top: 10px;
    margin-bottom: 20px;
}


 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
你可以使用一个 div 元素作为层,然后在该元素内部创建一个输入框和一个按钮来实现输入文字对话框。以下是一个示例: HTML 代码: ``` <div id="mask"> <div id="dialog"> <input type="text" id="input" placeholder="请输入文字..."> <button id="submit">确定</button> </div> </div> ``` CSS 代码: ``` #mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 9999; } #dialog { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; padding: 20px; border-radius: 5px; } #input { width: 100%; padding: 10px; margin-bottom: 10px; border: none; border-bottom: 1px solid #ccc; font-size: 16px; } #submit { display: block; width: 100%; padding: 10px; background-color: #009688; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; } #submit:hover { background-color: #008080; } ``` JavaScript 代码: ``` // 获取元素对象 var mask = document.getElementById('mask'); var input = document.getElementById('input'); var submit = document.getElementById('submit'); // 显示层 mask.style.display = 'block'; // 监听按钮点击事件 submit.addEventListener('click', function() { // 获取输入框的值 var text = input.value.trim(); // 隐藏层 mask.style.display = 'none'; // 处理输入框的值 // ... }); ``` 在 JavaScript 代码中,你可以根据你的实际需求来处理输入框的值。例如,你可以将它显示在页面上或者通过 Ajax 发送到服务器进行处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Stzyz_121314

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值