Skip to content

Commit 7310a16

Browse files
author
Cube
authored
Merge pull request #122 from Dynamsoft/_dev
Dev
2 parents 0a04644 + 707976c commit 7310a16

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

4.use-case/3.show-result-texts-on-the-video.html

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,9 @@
2121
https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#host-the-library-yourself-recommended
2222
-->
2323
<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>
3024
</head>
3125
<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>
3327
<div id="div-text-containers"></div>
3428
<script>
3529
if (location.protocol === "file:") {
@@ -95,13 +89,26 @@
9589
const convertedP2 = scanner.convertToPageCoordinates(p2);
9690

9791
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+
}
105112
textContainer.innerText = result.barcodeText;
106113
divTextContainers.append(textContainer);
107114

0 commit comments

Comments
 (0)