layui-layer independent component-pop-up layer introduction

Release: 2019-12-11 16:48:11
forward
2612 people have browsed it

layui-layer independent component-pop-up layer introduction

[Notes]

1. When using, please place the entire folder layer in any directory of your site, and just introduce layer.js. , except for jQuery, other files do not need to be introduced.

2. If your js import is processed through merging or you do not want to use the absolute path automatically obtained by layer, you can configure it through layer.config() (see the official website API page for details)

3. jquery requires 1.8

After downloading the layer, deploy it to any directory in your project (of course, we recommend placing it in the front-end related directory). You cannot move the file structure in the layer. Because they are an inseparable combination. Like this: (Special note: You need to introduce the entire layer folder into your file, not just the layer.js file)

layui-layer independent component-pop-up layer introduction

You don’t have to worry about those files What is it for? You only need to identify one file: layer.js. That’s right, when you try to present the layer on the page, you should do it like this: (the simplest example)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/layer.css"/>
        <style type="text/css">
            .btn{
                width: 100%;
                height: 50px;
                line-height: 50px;
                background: magenta;
                text-align: center;
                font-size: 15px;
            }
        </style>
    </head>
    <body>
        <div class="btn">点我</div>
        <!--你必须先引入jQuery1.8或以上版本-->
        <script src="js/jquery-2.1.0.js"></script>
        <script src="js/layer/layer.js"></script>
        <script>
            $(".btn").bind("click",function(){
                layer.msg(&#39;点我的人最美!&#39;);
            });
        </script>
    </body>
</html>
Copy after login
$("#btn").bind("click",function(){
        //layer.msg(&#39;点我的人最美!&#39;);
        layer.msg(&#39;此商品不存在或者已下架,看看其他商品吧!&#39;, {
        time: 3000
    });
});
Copy after login

More Example:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/layer.css"/>
        <style type="text/css">
            .btn:nth-child(odd){
                width: 100%;
                height: 50px;
                line-height: 50px;
                background: magenta;
                text-align: center;
                font-size: 15px;
            }
            .btn:nth-child(even){
                width: 100%;
                height: 50px;
                line-height: 50px;
                background: aqua;
                text-align: center;
                font-size: 15px;
            }
            #test5{
                text-align: center;
                width: 500px;
                margin-left: 500px;
            }
        </style>
    </head>
    <body>
        <div class="btn" id="btn">点我.btn</div>
        <div class="btn" id="test2">点我test2</div>
        <div class="btn" id="parentIframe">点我parentIframe</div>
        <div class="btn" id="test4">点我test4</div>
        <div class="btn" id="test5">点我test5</div>
        <!--你必须先引入jQuery1.8或以上版本-->
        <script src="js/jquery-2.1.0.js"></script>
        <script src="js/layer/layer.js"></script>
        <script>
        $(function(){
            $("#btn").bind("click",function(){
                layer.msg(&#39;点我的人最美!&#39;);
            });
            
            //弹出一个页面层
            $(&#39;#test2&#39;).on(&#39;click&#39;, function(){
              layer.open({
              type: 1,
              area: [&#39;600px&#39;, &#39;360px&#39;],
              shadeClose: true,   //点击遮罩关闭
              content: &#39;\<\div style="padding:20px;">自定义内容--添加自己需要的描述内容\<\/div>&#39;
              });
            });
            
            //弹出一个iframe层
            $(&#39;#parentIframe&#39;).on(&#39;click&#39;, function(){
              layer.open({
              type: 2,
              title: &#39;iframe父子操作&#39;,
              maxmin: true,
              shadeClose: true, //点击遮罩关闭层
              area : [&#39;800px&#39; , &#39;520px&#39;],
              content: &#39;parentIframe.html&#39;
              });
            });

            //弹出一个loading层
            $(&#39;#test4&#39;).on(&#39;click&#39;, function(){
              var ii = layer.load();
              //此处用setTimeout演示ajax的回调
              setTimeout(function(){
              layer.close(ii);
              }, 1000);
            });
            
            //弹出一个tips层
            $(&#39;#test5&#39;).on(&#39;click&#39;, function(){
              layer.tips(&#39;Hello tips!&#39;, &#39;#test5&#39;);
            });
            
        });
        </script>
    </body>
</html>
Copy after login
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/layer.css"/>
        <style type="text/css">
            .btn:nth-child(odd){
                width: 100%;
                height: 50px;
                line-height: 50px;
                background: magenta;
                text-align: center;
                font-size: 15px;
            }
            .btn:nth-child(even){
                width: 100%;
                height: 50px;
                line-height: 50px;
                background: aqua;
                text-align: center;
                font-size: 15px;
            }
            #test5{
                text-align: center;
                width: 100px;
                margin-left: 100px;
            }
        </style>
    </head>
    <body>
        <div class="btn" id="btn">点我.btn</div>
        <div class="btn" id="test2">点我test2</div>
        <div class="btn" id="parentIframe">点我parentIframe</div>
        <div class="btn" id="test4">点我test4</div>
        <div class="btn" id="test5">点我test5</div>
        
        <div class="btn" id="test6">点我test6</div>
        <div class="btn" id="test7">点我test7</div>
        <div class="btn" id="test8">点我test8</div>
        <div class="btn" id="test9">点我test9</div>
        
        <!--你必须先引入jQuery1.8或以上版本-->
        <script src="js/jquery-2.1.0.js"></script>
        <script src="js/layer/layer.js"></script>
        <script>
        $(function(){
            $("#btn").bind("click",function(){
                layer.msg(&#39;点我的人最美!&#39;);
            });
            
            //弹出一个页面层
            $(&#39;#test2&#39;).on(&#39;click&#39;, function(){
              layer.open({
              type: 1,
              area: [&#39;600px&#39;, &#39;360px&#39;],
              shadeClose: true,   //点击遮罩关闭
              content: &#39;\<\div style="padding:20px;">自定义内容--添加自己需要的描述内容\<\/div>&#39;
              });
            });
            
            //弹出一个iframe层
            $(&#39;#parentIframe&#39;).on(&#39;click&#39;, function(){
              layer.open({
              type: 2,
              title: &#39;iframe父子操作&#39;,
              maxmin: true,
              shadeClose: true, //点击遮罩关闭层
              area : [&#39;800px&#39; , &#39;520px&#39;],
              content: &#39;parentIframe.html&#39;
              });
            });

            //弹出一个loading层
            $(&#39;#test4&#39;).on(&#39;click&#39;, function(){
              var ii = layer.load();
              //此处用setTimeout演示ajax的回调
              setTimeout(function(){
                  layer.close(ii);
              }, 1000);
            });
            
            //弹出一个tips层
            $(&#39;#test5&#39;).on(&#39;click&#39;, function(){
              layer.tips(&#39;Hello tips!&#39;, &#39;#test5&#39;);
            });
            
            //======================================
            //多窗口模式,层叠置顶
            $(&#39;#test6&#39;).on(&#39;click&#39;, function(){
                layer.open({
                  type: 2 //此处以iframe举例
                  ,title: &#39;当你选择该窗体时,即会在最顶端&#39;
                  ,area: [&#39;390px&#39;, &#39;330px&#39;]
                  ,shade: 0
                  ,offset: [ //为了演示,随机坐标
                    Math.random()*($(window).height()-300)
                    ,Math.random()*($(window).width()-390)
                  ]
                  ,maxmin: true
                  ,content: &#39;settop.html&#39;
                  ,btn: [&#39;继续弹出&#39;, &#39;全部关闭&#39;] //只是为了演示
                  ,yes: function(){
                    $(that).click(); //此处只是为了演示,实际使用可以剔除
                  }
                  ,btn2: function(){
                    layer.closeAll();
                  }
                  
                  ,zIndex: layer.zIndex //重点1
                  ,success: function(layero){
                    layer.setTop(layero); //重点2
                  }
                });
            });
            
            
            
            //配置一个透明的询问框
            $(&#39;#test7&#39;).on(&#39;click&#39;, function(){
                layer.msg(&#39;大部分参数都是可以公用的<br>合理搭配,展示不一样的风格&#39;, {
                  time: 20000, //20s后自动关闭
                  btn: [&#39;明白了&#39;, &#39;知道了&#39;, &#39;哦&#39;]
                });
            });
                
            
            //示范一个公告层
            $(&#39;#test8&#39;).on(&#39;click&#39;, function(){
                layer.open({
                  type: 1
                  ,title: false //不显示标题栏
                  ,closeBtn: false
                  ,area: &#39;300px;&#39;
                  ,shade: 0.8
                  ,id: &#39;LAY_layuipro&#39; //设定一个id,防止重复弹出
                  ,resize: false
                  ,btn: [&#39;火速围观&#39;, &#39;残忍拒绝&#39;]
                  ,btnAlign: &#39;c&#39;
                  ,moveType: 1 //拖拽模式,0或者1
                  ,content: &#39;<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">内容<br>内容</div>&#39;
                  ,success: function(layero){
                    var btn = layero.find(&#39;.layui-layer-btn&#39;);
                    btn.find(&#39;.layui-layer-btn0&#39;).attr({
                      href: &#39;http://www.layui.com/&#39;
                      ,target: &#39;_blank&#39;
                    });
                  }
                });
            });
             
            //边缘弹出
            $(&#39;#test9&#39;).on(&#39;click&#39;, function(){
                layer.open({
                   type: 1
                   ,offset: &#39;c&#39; //具体配置参考:offset参数项(t、r、b、l、c)
                   ,content: &#39;<div style="padding: 20px 80px;">内容</div>&#39;
                   ,btn: &#39;关闭全部&#39;
                   ,btnAlign: &#39;c&#39; //按钮居中
                   ,shade: 0 //不显示遮罩
                   ,yes: function(){
                       layer.closeAll();
                  }
                });
            });


        });
        </script>
    </body>
</html>
Copy after login

For more layui knowledge, please pay attention to the layui usage tutorial column.

The above is the detailed content of layui-layer independent component-pop-up layer introduction. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template