Skip to content

Commit 6736b90

Browse files
author
Cube
authored
Merge pull request #130 from Dynamsoft/_dev
Dev
2 parents 1faf6e2 + 318b999 commit 6736b90

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
.bubble-box{
2020
max-width: 20rem; /* You are likely to change it */
2121
position: absolute;
22+
right: -999px;
2223
background: white;
2324
border-radius: 4px;
2425
padding: 4px;
2526
word-break: break-all;
2627
word-wrap: break-word;
2728
box-shadow: 5px 5px 5px 3px rgba(0,0,0,0.2);
28-
transform: translate(-50%, -4px);
29+
transform: translate(-50%, calc(-100% - 4px));
2930
}
3031
.bubble-box::after{
3132
content: '';
@@ -103,28 +104,33 @@
103104
y: Math.max(l.y1, l.y2, l.y3, l.y4),
104105
};
105106

106-
/**
107-
* 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document.
108-
* Then we can place a div element according to the converted coordinate.
109-
*/
110-
const convertedP1 = scanner.convertToPageCoordinates(p1);
111-
const convertedP2 = scanner.convertToPageCoordinates(p2);
112-
113107
divInf = document.createElement("div");
114108
divInf.className = 'bubble-box';
115109
const bodyStyle = getComputedStyle(document.body);
116110
if (bodyStyle.position === "static") {
111+
/**
112+
* 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document.
113+
* Then we can place a div element according to the converted coordinate.
114+
*/
115+
const convertedP1 = scanner.convertToPageCoordinates(p1);
116+
const convertedP2 = scanner.convertToPageCoordinates(p2);
117117
Object.assign(divInf.style, {
118118
left: `${(convertedP1.x + convertedP2.x) / 2}px`,
119-
bottom: `${document.documentElement.clientHeight - convertedP1.y}px`,
119+
top: `${convertedP1.y}px`,
120120
});
121121
} else { // if you set body `position` as `relative`, `absolute`, things can get complicated
122+
/**
123+
* 'convertToClientCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the viewport.
124+
* Then we can place a div element according to the converted coordinate.
125+
*/
126+
const convertedP1 = scanner.convertToClientCoordinates(p1);
127+
const convertedP2 = scanner.convertToClientCoordinates(p2);
122128
const bodyRect = document.body.getBoundingClientRect();
123129
const bodyBorderLeft = parseFloat(bodyStyle.borderLeftWidth);
124-
const bodyBorderBottom = parseFloat(bodyStyle.borderBottomWidth);
130+
const bodyBorderTop = parseFloat(bodyStyle.borderTopWidth);
125131
Object.assign(divInf.style, {
126132
left: `${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft}px`,
127-
bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom}px`,
133+
top: `${convertedP1.y - bodyRect.top - bodyBorderTop}px`,
128134
});
129135
}
130136
divInf.innerText = result.barcodeText;

0 commit comments

Comments
 (0)