<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>二维码生成器</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
.container {
text-align: center;
background-color: #fff;
padding: 25px;
border-radius: 15px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 400px;
}
h1 {
margin-bottom: 20px;
font-size: 24px;
color: #333;
}
input[type="text"] {
width: 100%;
padding: 12px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 16px;
box-sizing: border-box;
}
select {
width: 100%;
padding: 12px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 16px;
background-color: #fff;
cursor: pointer;
}
button {
padding: 12px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 8px;
cursor: pointer;
margin: 5px;
width: 100%;
font-size: 16px;
transition: background-color 0.3s ease, transform 0.2s ease;
}
button:hover {
background-color: #0056b3;
transform: scale(1.05);
}
button:active {
transform: scale(0.95);
}
.qr-code {
margin-top: 20px;
display: flex;
justify-content: center;
animation: fadeIn 0.5s ease;
}
.qr-code canvas {
max-width: 100%;
height: auto;
border: 1px solid #ccc;
border-radius: 8px;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>
</head>
<body>
<div class="container">
<h1>二维码生成器</h1>
<input type="text" id="inputText" placeholder="请输入网址或文本">
<select id="backgroundColor">
<option value="#ffffff">白色</option>
<option value="#ff0000">红色</option>
<option value="#00ff00">绿色</option>
<option value="#0000ff">蓝色</option>
<option value="#ffff00">黄色</option>
<option value="#ff00ff">粉色</option>
</select>
<button onclick="generateQRCode()">生成二维码</button>
<button onclick="saveQRCode()">保存二维码</button>
<div class="qr-code" id="qrCode"></div>
@菜鬼
</div>
<!-- 使用 QRCode.js 库 -->
<script src="https://cdn.jsdelivr.net/npm/qrcodejs/qrcode.min.js"></script>
<script>
let qrCodeInstance = null;
// 生成二维码
function generateQRCode() {
const inputText = document.getElementById('inputText').value;
const backgroundColor = document.getElementById('backgroundColor').value;
const qrCodeDiv = document.getElementById('qrCode');
if (!inputText) {
alert('请输入网址或文本');
return;
}
// 清空之前的二维码
qrCodeDiv.innerHTML = '';
// 生成二维码
qrCodeInstance = new QRCode(qrCodeDiv, {
text: inputText,
width: 200,
height: 200,
colorDark: "#000000", // 二维码颜色
colorLight: backgroundColor, // 背景颜色
correctLevel: QRCode.CorrectLevel.H
});
}
// 保存二维码
function saveQRCode() {
const qrCodeCanvas = document.querySelector('.qr-code canvas');
if (!qrCodeCanvas) {
alert('请先生成二维码');
return;
}
// 创建一个新的 canvas 用于保存
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = qrCodeCanvas.width;
canvas.height = qrCodeCanvas.height;
// 填充背景颜色
const backgroundColor = document.getElementById('backgroundColor').value;
context.fillStyle = backgroundColor;
context.fillRect(0, 0, canvas.width, canvas.height);
// 绘制二维码
context.drawImage(qrCodeCanvas, 0, 0);
// 保存为图片
const link = document.createElement('a');
link.href = canvas.toDataURL('image/png');
link.download = 'qrcode.png';
link.click();
}
</script>
</body>
</html>
二维码生成器
一言准备中...
本站收集的资源仅供内部学习研究软件设计思想和原理使用,学习研究后请自觉删除,请勿传播,因未及时删除所造成的任何后果责任自负。
如果用于其他用途,请购买正版支持作者,谢谢!若您认为 www.5iml.com 发布的内容若侵犯到您的权益,请联系站长邮箱:858585857@qq.com 进行删除处理。
本站资源大多存储在云盘,如发现链接失效,请联系我们,我们会第一时间更新。
文章很赞!支持一下吧
还没有人为TA充电
为TA充电
-
支付宝扫一扫
-
微信扫一扫
感谢支持
文章很赞!支持一下吧
这一切,似未曾拥有