feat: best scale auto-choose
This commit is contained in:
parent
a0259cc51d
commit
326844fe1c
1 changed files with 21 additions and 3 deletions
24
script.js
24
script.js
|
@ -127,9 +127,27 @@ addEventListener('DOMContentLoaded', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
{ // Choose best scale for screen height
|
{ // Choose best scale for screen height
|
||||||
const height = document.documentElement.clientHeight;
|
let padding = getComputedStyle(document.body).paddingBottom
|
||||||
const padding = getComputedStyle(document.body).paddingTop;
|
// remove `px` at the end and convert to number
|
||||||
// TODO
|
padding = Number(padding.slice(0, padding.length - 2))
|
||||||
|
|
||||||
|
// compute available height
|
||||||
|
const height =
|
||||||
|
document.documentElement.clientHeight
|
||||||
|
- canvas.offsetTop // substract height of everything above canvas
|
||||||
|
- padding // substract body padding
|
||||||
|
|
||||||
|
const width =
|
||||||
|
document.documentElement.clientWidth
|
||||||
|
- padding * 2
|
||||||
|
|
||||||
|
options.scale.value = Math.max(
|
||||||
|
intDiv(
|
||||||
|
width < height ? width : height,
|
||||||
|
25, // divide least dimension by QR version 2 size
|
||||||
|
),
|
||||||
|
10, // minimum scale for this auto-detect algorithm
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // QR version related stuff
|
{ // QR version related stuff
|
||||||
|
|
Loading…
Add table
Reference in a new issue