Skip to content

Commit 5d02690

Browse files
committed
fix #2,support set width and height of the parent container
1 parent e7e016a commit 5d02690

File tree

7 files changed

+24
-29
lines changed

7 files changed

+24
-29
lines changed

dist/vue-signature.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-signature.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
56
<title>vue-signature</title>
67
</head>
78
<body>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-signature",
33
"description": "Electronic signature",
4-
"version": "1.2.0",
4+
"version": "1.3.0",
55
"author": "Shayne Wang <[email protected]>",
66
"private": false,
77
"license": "MIT",

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<vueSignature ref="signature" :sigOption="option"></vueSignature>
3+
<vueSignature ref="signature" :sigOption="option" :w="'800px'" :h="'400px'"></vueSignature>
44
<vueSignature ref="signature" :sigOption="option"></vueSignature>
55
<button @click="save">保存</button>
66
<button @click="clear">清除</button>

src/lib/vue-signature.vue

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
2+
<div :style="{width:w,height:h}">
33
<canvas :id="uid" class="canvas" :data-uid="uid"></canvas>
44
</div>
55

@@ -13,6 +13,14 @@
1313
sigOption: {
1414
type:Object,
1515
default:()=>{penColor : 'rgb(0, 0, 0)'},
16+
},
17+
w:{
18+
type:String,
19+
default:"100%"
20+
},
21+
h:{
22+
type:String,
23+
default:"100%"
1624
}
1725
},
1826
data(){
@@ -31,28 +39,11 @@
3139
var _this = this;
3240
var canvas = document.getElementById(_this.uid)
3341
_this.sig = new SignaturePad(canvas,_this.sigOption);
34-
function isPC() {
35-
var userAgentInfo = navigator.userAgent;
36-
var Agents = ["Android", "iPhone",
37-
"SymbianOS", "Windows Phone",
38-
"iPad", "iPod"];
39-
var flag = true;
40-
for (var v = 0; v < Agents.length; v++) {
41-
if (userAgentInfo.indexOf(Agents[v]) > 0) {
42-
flag = false;
43-
break;
44-
}
45-
}
46-
return flag;
47-
}
4842
function resizeCanvas() {
49-
if(isPC){
50-
canvas.width = window.innerWidth;
51-
canvas.height = window.innerHeight;
52-
}else{
53-
canvas.width = canvas.offsetWidth;
54-
canvas.height = canvas.offsetHeight;
55-
}
43+
var ratio = Math.max(window.devicePixelRatio || 1, 1);
44+
canvas.width = canvas.offsetWidth * ratio;
45+
canvas.height = canvas.offsetHeight * ratio;
46+
canvas.getContext("2d").scale(ratio, ratio);
5647
}
5748
window.addEventListener("resize", resizeCanvas);
5849
resizeCanvas();
@@ -77,5 +68,8 @@
7768
</script>
7869

7970
<style>
80-
71+
canvas {
72+
width: 100%;
73+
height: 100%;
74+
}
8175
</style>

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
output: {
88
path: path.resolve(__dirname, './dist'),
99
publicPath: '/dist/',
10-
// filename: 'build.js'
10+
// filename: 'build.js',
1111
filename:"vue-signature.js",
1212
library: 'vue-signature',
1313
libraryTarget: 'umd',

0 commit comments

Comments
 (0)