生成二维码名片

二维码名片

填写信息生成二维码,扫码添加到手机通讯录

知识点

  • 内容显示部分采用毛玻璃效果
    • 使用伪元素覆盖,并同时采用blur()滤镜
  • 使用qrcode.js生成二维码
    • 使用var qr = new QRCode(targId, info);实现

效果图

这里写图片描述

这里写图片描述

代码

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Calling card</title>
    <link rel="stylesheet" href="css/reset.css">
    <style>
        body, section::before {
            background: #339955 url(img/background.jpg) 0 / cover fixed;
        }
        section {
            position: absolute;
            width: 700px;
            height: 280px;
            left: calc(50% - 350px);
            top: calc(50% - 140px);
            background: hsla(0, 0%, 100%, 0.3);
            overflow: hidden;
        }   
        section::before {
            content: '';
            position: absolute;
            top: 0; right: 0; bottom: 0; left: 0;
            filter: blur(20px);
            z-index: -1;
            margin: -30px;
        }
        section .message {
            position: absolute;
            width: 400px;
            height: 250px;
            top: calc(50% - 125px);
            left: 2%;
            /*border: 1px solid black;*/
        }
        section .message ul {
            width: 400px;
            height: 220px;
            margin: 25px 0;
        }
        section .message ul li {
            margin: 10px 5px;
            float: left;
            font-size: 15px;
            /*color: #000;*/
            font-weight: bold;
        }
        section .message ul li input {
            height: 20px;
            width: 150px;
            text-indent: 5px;
            border: 0;
            border-radius: 3px;
        }
        section .message ul li .button {
            position: absolute;
            width: 300px;
            height: 35px;
            left: calc(50% - 150px);
            top: calc(100% - 70px);
            line-height: 35px;
            text-align: center;
            color: #fff;
            border-radius: 5px;
            background: rgba(50, 248, 50, 0.5);
            cursor: pointer;
        }
        .qrcode {
            width: 200px;
            height: 200px;
            float: right;
            position: relative;
            margin: 40px 30px -10px 0px;
            background: #eee;
            border: 1px solid black;
            cursor: default;
        }
        .qrcode h2 {
            position: absolute;
            height: 15px;
            width: 100px;
            top: calc(50% - 40px);
            left: calc(50% - 50px);
        }
    </style>
</head>
<body>
    <section>
        <div class="message" id="message">
            <ul>
                <li><span>姓名: </span><input type="text"></li>
                <li><span>公司: </span><input type="text"></li>
                <li><span>职位: </span><input type="text"></li>
                <li><span>邮箱: </span><input type="email"></li>
                <li><span>电话: </span><input type="tel"></li>
                <li><span>备注: </span><input type="text"></li>
                <li><div class="button" id="btn">点击生成二维码</div></li>
            </ul>
        </div>
        <div class="qrcode" id="qrcode"><h2>点击按钮<br/>生成二维码</h2></div>
    </section>  
    <script type="text/javascript" src='js/qrcode.min.js'></script>
    <script type="text/javascript" src='js/myJS.js'></script>
</body>
</html>
var loadEvent = function(fn) { 
    var oldonload = window.onload; 
    if (typeof window.onload != 'function') { 
        window.onload = fn; 
    } else { 
        window.onload = function() { 
            oldonload(); 
            fn(); 
        };
    } 
};

var buildQrcode = function (info, target, targetName) {
    target.innerHTML = '';

    var qr = new QRCode(targetName, {
        text: info,
        width: 200,
        height: 200,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });
};

var setButtoonClick = function (btn, inputArr) {

    var textArr = ['FN:', 'ORG:', 'WORK:', 'EMAIL:', 'TEL:', 'DESC:'],
        info = null,
        infoEnd = null,
        i,
        len;

    btn.onclick = function () {

        info = '';
        info = 'BEGIN:VCARD\n';
        infoEnd = 'END:VCARD';

        if (textArr.length === inputArr.length) {
            for (i = 0, len = textArr.length; i < len; i++) {
                info += textArr[i] + inputArr[i].value + '\n';
            }
            info += infoEnd;

            if (document.getElementById('qrcode')) {
                var qrcode = document.getElementById('qrcode');
                buildQrcode(info, qrcode, 'qrcode');
            }
        }
    };
};

var perparCard = function () {

    var message = null,
        btn = null;

    if (!document.getElementById || !document.getElementById('message') || !document.getElementById('btn')) {
        return false;
    }   

    message = document.getElementById('message');
    inputArr = message.getElementsByTagName('input');
    btn = document.getElementById('btn');

    setButtoonClick(btn, inputArr);
};

loadEvent(perparCard);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值