|
21 | 21 | https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#host-the-library-yourself-recommended |
22 | 22 | --> |
23 | 23 | <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.6.20/dist/dbr.js"></script> |
24 | | - <style> |
25 | | - * { |
26 | | - margin: 0; |
27 | | - padding: 0; |
28 | | - } |
29 | | - </style> |
30 | 24 | </head> |
31 | 25 | <body> |
32 | | - <div id="div-ui-container" style="width: 100%; height: 100vh"></div> |
| 26 | + <div id="div-ui-container" style="width: 100%; height: 90vh"></div> |
33 | 27 | <div id="div-text-containers"></div> |
34 | 28 | <script> |
35 | 29 | if (location.protocol === "file:") { |
|
95 | 89 | const convertedP2 = scanner.convertToPageCoordinates(p2); |
96 | 90 |
|
97 | 91 | textContainer = document.createElement("div"); |
98 | | - Object.assign(textContainer.style, { |
99 | | - position: "absolute", |
100 | | - left: convertedP1.x + "px", |
101 | | - right: document.documentElement.clientWidth - convertedP2.x + "px", |
102 | | - bottom: document.documentElement.clientHeight - convertedP1.y + "px", |
103 | | - color: "#FE8E14", |
104 | | - }); |
| 92 | + const bodyStyle = getComputedStyle(document.body); |
| 93 | + if (bodyStyle.position !== "static") { |
| 94 | + const rect = document.body.getBoundingClientRect(); |
| 95 | + const borderWidth = parseInt(bodyStyle.borderWidth); |
| 96 | + Object.assign(textContainer.style, { |
| 97 | + position: "absolute", |
| 98 | + left: convertedP1.x - rect.left - borderWidth + "px", |
| 99 | + right: rect.right - convertedP2.x - borderWidth + "px", |
| 100 | + bottom: rect.bottom - convertedP1.y - borderWidth + "px", |
| 101 | + color: "#FE8E14", |
| 102 | + }); |
| 103 | + } else { |
| 104 | + Object.assign(textContainer.style, { |
| 105 | + position: "absolute", |
| 106 | + left: convertedP1.x + "px", |
| 107 | + right: document.documentElement.clientWidth - convertedP2.x + "px", |
| 108 | + bottom: document.documentElement.clientHeight - convertedP1.y + "px", |
| 109 | + color: "#FE8E14", |
| 110 | + }); |
| 111 | + } |
105 | 112 | textContainer.innerText = result.barcodeText; |
106 | 113 | divTextContainers.append(textContainer); |
107 | 114 |
|
|
0 commit comments