Skip to content

Commit 318b999

Browse files
committed
Update 3.show-result-texts-on-the-video.html
1 parent 9c08b34 commit 318b999

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,33 @@
104104
y: Math.max(l.y1, l.y2, l.y3, l.y4),
105105
};
106106

107-
/**
108-
* 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document.
109-
* Then we can place a div element according to the converted coordinate.
110-
*/
111-
const convertedP1 = scanner.convertToPageCoordinates(p1);
112-
const convertedP2 = scanner.convertToPageCoordinates(p2);
113-
114107
divInf = document.createElement("div");
115108
divInf.className = 'bubble-box';
116109
const bodyStyle = getComputedStyle(document.body);
117110
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);
118117
Object.assign(divInf.style, {
119118
left: `${(convertedP1.x + convertedP2.x) / 2}px`,
120119
top: `${convertedP1.y}px`,
121120
});
122121
} 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);
123128
const bodyRect = document.body.getBoundingClientRect();
124129
const bodyBorderLeft = parseFloat(bodyStyle.borderLeftWidth);
125130
const bodyBorderTop = parseFloat(bodyStyle.borderTopWidth);
126131
Object.assign(divInf.style, {
127-
left: `${(convertedP1.x + convertedP2.x) / 2 - (bodyRect.left + document.documentElement.scrollLeft) - bodyBorderLeft}px`,
128-
top: `${convertedP1.y - (bodyRect.top + document.documentElement.scrollTop) - bodyBorderTop}px`,
132+
left: `${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft}px`,
133+
top: `${convertedP1.y - bodyRect.top - bodyBorderTop}px`,
129134
});
130135
}
131136
divInf.innerText = result.barcodeText;

0 commit comments

Comments
 (0)