Juqery弹出框屏幕居中显示

弹出框

HTML代码:
 <span class="spanbb">上传</span>
 点击spanbb时弹出
 <div class="niubi" style="opacity: 1;top: 100px;visibility: hidden;">
			<form id="f" action="" method="post" enctype="multipart/form-data" class="file_form">
				 <a href="javascript:void(0);" class="btn_addPic"><span><em>+</em>添加图片</span>

                 <input type="file" name="metail" multiple="multiple" class="filePrew cfText" cf_fieldlength="100" cf_elementtype="field" cf_iscreateid="1" cf_widgetid="cf_text"  cf_modelitemname="文件上传"></a>
                 <input id="UploadFile" type="hidden" name="metailId" value="UploadFile" class="filePrew cfText" cf_fieldlength="100" cf_elementtype="field" cf_iscreateid="1" cf_widgetid="cf_text" cf_modelitemid="UploadFile"></a>
                 <input type="hidden" name="dataId" value="${dataId}">
                 <input type="button" onclick="updateMetail()" value="提交" class="submitbtn" >
                 <input type="reset" value="重置" id="reset" class="submitbtn">
			</form>
            <a class="close-reveal-modal">×</a>
        </div>
		<div class="fiem" style="display: none; cursor: pointer;">

		</div>
CSS样式:
.niubi {
    visibility: hidden;
    top: 100px;
    left: 50%;
    margin-left: -300px;
    width: 520px;
    background: #eee url(../../images/modal-gloss.png) no-repeat -200px -80px;
    position: absolute;
    z-index: 101;
    padding: 30px 40px 34px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-box-shadow: 0 0 10px rgba(0,0,0,.4);
    -webkit-box-shadow: 0 0 10px rgba(0,0,0,.4);
    -box-shadow: 0 0 10px rgba(0,0,0,.4);
}
.file_form {
    text-align: center;
    width: 327px;
    margin: 0 auto;
}
.close-reveal-modal {
    font-size: 22px;
    line-height: .5;
    position: absolute;
    top: 8px;
    right: 11px;
    color: #aaa;
    font-weight: bold;
    cursor: pointer;
}
.btn_addPic {
    display: inline-block;
    position: relative;
    height: 39px;
    overflow: hidden;
    padding: 0 30px;
    border: 1px solid #EBEBEB;
    background: #f1fbfe;
    color: #999999;
    width: 83%;
    font: 14px/39px 'MicroSoft Yahei','Simhei';
    cursor: pointer;
    text-align: center;
}
.filePrew {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 39px;
    cursor: pointer;
    opacity: 0;
    filter: alpha(opacity: 0);
}
.submitbtn {
    border: none;
    font-size: 14px;
    background: #1ca6e8;
    color: #fff;
    width: 80px;
    height: 40px;
    margin-top: 10px;
    cursor: pointer;
}
.fiem {
    position: fixed;
    height: 100%;
    width: 100%;
    background: #000;
    background: rgba(0,0,0,.8);
    z-index: 100;
    display: none;
    top: 0;
    left: 0;
}
jquery代码
<script type="text/javascript">
            $(function(){
                $(".spanbb").click(function(){
                    var screenWidth = parseInt($(window).width());
                    var screenHeight = parseInt($(window).height()); //当前浏览器窗口的 宽高
                    var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度
                    var sss = $(this).attr('id');
                    var niubiWidth=parseInt($(".niubi").width());
                    var niubiHeight=parseInt($(".niubi").height());
                    var objLeft = (screenWidth - niubiWidth)/4;
                    var objTop = (screenHeight - niubiHeight)/4 + scrolltop;
                    var nameId = $('.filePrew').attr('value',sss)
                    $(".niubi").css({"visibility":"visible","top":objTop + 'px',"overflow": "hidden"});
                    $("body").height(screenHeight).css({"overflow": "hidden"});
                    $(".fiem").height(screenHeight).css({"overflow": "hidden"}).fadeIn(300);
                })
                $("#reset").click(function(){
                    $(this).parents('.niubi').find('.btn_addPic span').html("<em>+</em>添加图片");
                })
                $(".fiem").click(function(){
                    var reg = /[^\\\/]*[\\\/]+/g;
                    var name = $(this).siblings(".niubi").find('.file_form .btn_addPic .filePrew').val().replace(reg, '');
                    if(name != ''){
                        var text =name.substr();//获取没有后缀的名称
                        var mbmb = $(this).siblings(".niubi").find('.file_form .btn_addPic .filePrew').val('');
                        $(this).siblings('.niubi').find('.btn_addPic span').html("<em>+</em>添加图片");
                    }
                    $(".niubi").css("visibility","hidden");

                    $("body").css({"overflow": "auto","height":"auto"});
                    $(this).fadeOut(300);
                })
                $(".close-reveal-modal").click(function(){
                    var reg = /[^\\\/]*[\\\/]+/g;
                    var name = $(this).parents(".niubi").find('.file_form .btn_addPic .filePrew').val().replace(reg, '');
                    if(name != ''){
                        var text =name.substr();//获取没有后缀的名称
                        var mbmb = $(this).parents(".niubi").find('.file_form .btn_addPic .filePrew').val('');
                        $(this).parents('.niubi').find('.btn_addPic span').html("<em>+</em>添加图片");
                    }
                    $(".niubi").css("visibility","hidden");
                    $("body").css({"overflow": "auto","height":"auto"});
                    $('.fiem').fadeOut(300);
                })
            })
        </script>

根据自己的项目需求更改的,看不懂欢迎留言

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【1】项目代码完整且功能都验证ok,确保稳定可靠运行后才上传。欢迎下载使用!在使用过程中,如有问题或建议,请及时私信沟通,帮助解答。 【2】项目主要针对各个计算机相关专业,包括计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师或企业员工使用。 【3】项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 【4】如果基础还行,或热爱钻研,可基于此项目进行二次开发,DIY其他不同功能,欢迎交流学习。 【注意】 项目下载解压后,项目名字和项目路径不要用中文,否则可能会出现解析不了的错误,建议解压重命名为英文名字后再运行!有问题私信沟通,祝顺利! 基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值