原版:github
https://github.com/davidshimjs/qrcodejs
原版不支持自定义边框参数。于是网上找了一个改动的方案:
https://blog.csdn.net/weixin_44038563/article/details/106907424
它的代码时写死边框宽度和颜色的,我做了优化,支持自定义像素和颜色。
改动如下。
355行
var borderWidth = htOption.borderWidth || 0;
this._elCanvas.width = htOption.width + borderWidth * 2;
this._elCanvas.height = htOption.height + borderWidth * 2;
388行
388
var borderColor = _htOption.borderColor || ''; //#ff0000
var borderWidth = _htOption.borderWidth || 0;
if(borderColor && borderWidth) {
_oContext.fillStyle = borderColor;
_oContext.fillRect(0, 0, _htOption.width + borderWidth *2, _htOption.height + borderWidth *2);
}
参数定义:
var codeObj = new QRCode(jqDom[0], {
width: 120,
height: 120,
borderWidth : 15,
borderColor : '#ffffff',
});
codeObj.makeCode("xxxxx内容");
下载链接:
qrcode.js下载链接