zoukankan      html  css  js  c++  java
  • 自己写的遮罩层效果

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="遮罩层.aspx.cs" Inherits="JQUERY练习.遮罩层" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>

        <script src="js/jquery-1.4.2.js" type="text/javascript"></script>
            <script language="javascript" type="text/javascript">
                $(function() {
                    $("#divtest").click(function(e) {
                        e.preventDefault();
                        var div = $("#top");
                        //获取弹出层的宽和高
                        divwidth = div.width();
                        divheight = div.height();
                        //获取文档的宽度和高度
                        var docwidth = $(document).width();
                        var docheight = $(document).height();

                        var clientwidth, clientheight, scrolltop, scrollleft;
                        //获取当前窗口的宽和高
                        clientwidth = $(window).width();
                        clientheight = $(window).height();

                        div.show();
                        div.css({ "left": (clientwidth - divwidth) / 2, "top": (clientheight - divheight) / 2 });
                        $("#bottom").show().css({ "width": docwidth, "height": docheight });


                        //当改变窗口大小的时候
                        $(window).resize(function() {
                            clientheight = $(window).height();
                            clientwidth = $(window).width();
                            div.css({ "left": (clientwidth - divwidth) / 2, "top": (clientheight - divheight) / 2 });
                            $("#bottom").show().css({ "width": docwidth, "height": docheight });
                        });
                        //当滚动滚动条时
                        $(window).scroll(function() {
                            //获取滚动条的scrolltop和scrollleft
                            scrollleft = $(document).scrollLeft();
                            scrolltop = $(document).scrollTop();
                            //获取当前窗口的大小
                            clientheight = $(window).height();
                            clientwidth = $(window).width();
                            div.css({ "left": (clientwidth - divwidth) / 2 + scrollleft, "top": (clientheight - divheight) / 2 + scrolltop });
                            $("#bottom").css({ "width": docwidth, "height": docheight });
                        });
                    });

                   $("#top input").click(function() {
                        $("#top,#bottom").css("display", "none");
                    });
                    
                });
                
        </script>
        <style>
            #top{400px;height:200px;background-color:White;position:absolute;z-index:500;display:none;}
            #bottom{100%;height:100%;top:0;left:0;background-color:#cccccc;position:absolute;z-index:499;display:none;opacity:0.5;}
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="divtest">点击我<a href="http://www.baidu.com">百度</a></div><br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
    &nbsp;<p></p>

        
        <div id="bottom"></div>
        <div id="top">这是弹出窗口<input type="button" value="关闭" /></div>
        </form>
    </body>
    </html>

  • 相关阅读:
    css backgroud属性与雪碧技术
    css margin 外边距塌陷问题
    css 浮动元素与清除浮动
    css 盒模型的概念与使用
    七年iOS架构师教你如何一举拿下35K的Offer,(附面试技巧)
    iOS开发者月薪想要突破30K,需要经历+提升些什么?
    月薪 8K 与30K的程序员 区别到底在哪里?
    那些月薪35K以上的iOS开发者 都掌握了什么技能?
    从事 iOS 开发8年的面经——送给准备跳槽的你!
    想进BAT大厂的 iOS程序员,看完这个你还觉得Offer难拿吗???
  • 原文地址:https://www.cnblogs.com/zpc870921/p/2640583.html
Copyright © 2011-2022 走看看