Skip to content

Commit 8af952d

Browse files
authored
bubble box
1 parent 7310a16 commit 8af952d

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,33 @@
1515
<title>
1616
Dynamsoft Barcode Reader Sample - Show result texts on the video
1717
</title>
18+
<style>
19+
.div-inf{
20+
position: absolute;
21+
background: white;
22+
border: 4px solid black;
23+
padding: 4px;
24+
}
25+
.div-inf::after{
26+
content: '';
27+
position: absolute;
28+
bottom: -8px;
29+
background: white;
30+
border-left: 8px solid white;
31+
border-bottom: 8px solid white;
32+
border-right: 8px solid white;
33+
}
34+
</style>
35+
</head>
36+
<body>
37+
<div id="div-ui-container" style="width: 100%; height: 90vh"></div>
38+
<div id="div-information-containers"></div>
1839
<!--
1940
This sample makes use of the library hosted by the CDN jsDelivr. If you would rather use the
2041
library offline. Please see the guide on how to host the library:
2142
https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#host-the-library-yourself-recommended
2243
-->
2344
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js"></script>
24-
</head>
25-
<body>
26-
<div id="div-ui-container" style="width: 100%; height: 90vh"></div>
27-
<div id="div-text-containers"></div>
2845
<script>
2946
if (location.protocol === "file:") {
3047
const message = `The page is opened via file:// and "BarcodeScanner" may not work properly. Please open the page via https:// or host it on "http://localhost/".`;
@@ -47,7 +64,7 @@
4764
* LICENSE ALERT - THE END
4865
*/
4966

50-
const divTextContainers = document.querySelector("#div-text-containers");
67+
const divInfContainers = document.querySelector("#div-information-containers");
5168
let scanner;
5269

5370
(async () => {
@@ -68,7 +85,7 @@
6885
console.log(results);
6986

7087
// Clear previous result text elements.
71-
divTextContainers.innerText = "";
88+
divInfContainers.innerText = "";
7289

7390
for (let result of results) {
7491
const l = result.localizationResult;
@@ -88,29 +105,26 @@
88105
const convertedP1 = scanner.convertToPageCoordinates(p1);
89106
const convertedP2 = scanner.convertToPageCoordinates(p2);
90107

91-
textContainer = document.createElement("div");
108+
divInf = document.createElement("div");
109+
divInf.className = 'div-inf';
92110
const bodyStyle = getComputedStyle(document.body);
93111
if (bodyStyle.position !== "static") {
94112
const rect = document.body.getBoundingClientRect();
95113
const borderWidth = parseInt(bodyStyle.borderWidth);
96-
Object.assign(textContainer.style, {
97-
position: "absolute",
114+
Object.assign(divInf.style, {
98115
left: convertedP1.x - rect.left - borderWidth + "px",
99116
right: rect.right - convertedP2.x - borderWidth + "px",
100117
bottom: rect.bottom - convertedP1.y - borderWidth + "px",
101-
color: "#FE8E14",
102118
});
103119
} else {
104-
Object.assign(textContainer.style, {
105-
position: "absolute",
120+
Object.assign(divInf.style, {
106121
left: convertedP1.x + "px",
107122
right: document.documentElement.clientWidth - convertedP2.x + "px",
108123
bottom: document.documentElement.clientHeight - convertedP1.y + "px",
109-
color: "#FE8E14",
110124
});
111125
}
112-
textContainer.innerText = result.barcodeText;
113-
divTextContainers.append(textContainer);
126+
divInf.innerText = result.barcodeText;
127+
divInfContainers.append(divInf);
114128

115129
/**
116130
* You can also add more information, such as displaying product images.

0 commit comments

Comments
 (0)