Layer 简单改造封装

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="layer_mobile/need/layer.css">
    <script src="jquery-2.1.4.min.js"></script>
    <script src="layer_mobile/layer.js"></script>
    <script src="layer_mobile/layeropen.js"></script>
    <title>Layers简单封装</title>
    <style>
        /*layer添加关闭按钮*/
        .close{
            position:absolute;
            right:-8px;
            top:-8px;
            border-radius:50%;
            width:20px;
            height:20px;
            z-index: 1000;
            background-size: 100% 100%;
            background-image: url("./close.png")
        }
    </style>
</head>
<body>
<div class="center">中间弹窗</div>
<div class="btm">底部弹窗</div>
<div class="custom">自定义风格</div>

<div class="layer_content" style="display: none">
    内容
</div>
<script >
    $(document).ready(function(){

        $('.center').on('click',function(){
            PageCenter('layer_content')
        })
        $('.btm').on('click',function(){
            PageBtm('layer_content')
        })
        $('.custom').on('click',function(){
            CustomStyle('layer_content')
        })
        $(document).on('click','.close',function(){
            console.log('close');
            layer.closeAll()
        })

    });
</script>
</body>
</html>

layeropen.js

function PageCenter(ClassName){
    //页面层
    layer.open({
        type:1
        ,content: $('.' + ClassName).html()
        ,anim: 'scale'
        ,style: "position:fixed; height: 300px;top:50%;margin-top:-150px;width: 300px;left:50%; margin-left:-150px; padding:0 0; border:none;background-size: 100% 100%;background-image: url('/child/img/idxbg.jpg')"
        ,yes: function(index){
            alert('点击了是')
            layer.close(index)
        }
        ,success: function(elem){
            $('.layui-m-layerchild').append('<div class="close"></div>');
        }
    });
}

function PageBtm(ClassName){
    //底部页面层
    layer.open({
        type: 1
        ,content: $('.' + ClassName).html()
        ,anim: 'up'
        ,style: 'position:fixed; bottom:0; left:0; width: 100%; height: 272px; padding:10px 0; border:none;'
        ,closeBtn:[0,true]
        ,success: function(elem){
            $('.layui-m-layerchild').append('<div class="close"></div>');
        }
    });
}


function CustomStyle(ClassName){
    //自定义标题风格
    layer.open({
        content: $('.' + ClassName).html()
    });
}

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值