仿微信弹出二维码

使用jquery插件生成二维码,然后弹出它。

先在页面引入:

<script src="./jquery-3.5.1.min.js"></script>
<script src="./jquery.qrcode.min.js"></script>

这是弹出框主体: 

    <div id="app">
        <p><a target="_blank" id="ercode">微信分享</a></p>
    </div>
    <div id="share_qrcode" class="share_qrcode">
        <div class="code_head">
            <span>保存二维码,分享到微信朋友圈</span>
            <p class="code_close" id="close">×</p>
        </div>
        <div id="code" class="code_main"></div>
        <div class="code_foot">
            <p>扫一扫,打开网页</p>
        </div>
    </div>
    <script>
        $(function() {
            function popup(popupName) {
                var sHeight = $(document).scrollTop();
                var wHeight = $(window).height();
                var wWidth = $(window).width();
                var popupHeight = $('#share_qrcode').height();
                var popupWeight = $('#share_qrcode').width();
                var posiTop = (wHeight - popupHeight) / 2 + sHeight;
                var posiLeft = (wWidth - popupWeight) / 2;
                console.log("sHeight:" + sHeight + ",窗口宽度:" + wWidth + ",窗口高度:" + wHeight + ",popupHeight:" + popupHeight + ",popupWeight" + popupWeight)
                popupName.css({
                    "left": posiLeft + "px"
                })
            }

            $('#ercode').click(function() {
                popup($('#share_qrcode'));
                $('#share_qrcode').fadeIn();
            });


            $('#close').on('click', function() {
                $('#share_qrcode').fadeOut();
            })

        })
    </script>

这个是生成二维码的:

<script>
    //二维码分享
    var url = window.location.href;
    $('#code').qrcode({
        text: url,
        render: "table", //table方式
        width: 200, //宽度
        height: 200, //高度
    });
</script>

这是弹出框样式:

        .share_qrcode {
            position: absolute;
            padding: 10px;
            width: 280px;
            height: 340px;
            background-color: #fff;
            border: 1px solid #d8d8d8;
            z-index: 990;
            font-size: 12px;
            display: none;
            left: 50%;
        }

        .share_qrcode .code_head {
            font-size: 12px;
            font-weight: bold;
            text-align: left;
            line-height: 16px;
            height: 16px;
            position: relative;
            color: #000;
        }

        .share_qrcode .code_close {
            width: 16px;
            height: 16px;
            position: absolute;
            right: 0;
            top: 0;
            color: #999;
            text-decoration: none;
            font-size: 16px;
        }
        .code_main {
            /* width: 200px; */
            /* height: 200px; */
            padding: 15px 10px;
            margin: 0 auto;
        }

        #code table {
            margin: 0 auto;
        }

        .code_foot {
            font-size: 12px;
            line-height: 22px;
            color: #666;
            text-align: left;
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值