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
|
||||
const height = document.documentElement.clientHeight;
|
||||
const padding = getComputedStyle(document.body).paddingTop;
|
||||
// TODO
|
||||
let padding = getComputedStyle(document.body).paddingBottom
|
||||
// remove `px` at the end and convert to number
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue