Skip to content

Commit 4cbcca2

Browse files
author
Cube
authored
Merge pull request #126 from Dynamsoft/Keillion-patch-2
transform: translateX(-50%)
2 parents 8ff04b9 + ffbdc4b commit 4cbcca2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
</title>
1818
<style>
1919
.bubble-box{
20+
max-width: 20rem; /* You are likely to change it */
2021
position: absolute;
2122
background: white;
2223
border-radius: 4px;
2324
padding: 4px;
2425
word-break: break-all;
2526
word-wrap: break-word;
2627
box-shadow: 5px 5px 5px 3px rgba(0,0,0,0.2);
28+
transform: translateX(-50%);
2729
}
2830
.bubble-box::after{
2931
content: '';
@@ -110,25 +112,20 @@
110112

111113
divInf = document.createElement("div");
112114
divInf.className = 'bubble-box';
113-
// define width of the bubble box
114-
const divInfWidth = "20rem";
115-
divInf.style.width = divInfWidth;
116115
const divInfVerticalOffset = 4; //px
117116
const bodyStyle = getComputedStyle(document.body);
118117
if (bodyStyle.position === "static") {
119118
Object.assign(divInf.style, {
120-
left: `calc(${(convertedP1.x + convertedP2.x) / 2}px - ${divInfWidth} / 2)`,
119+
left: `${(convertedP1.x + convertedP2.x) / 2}px`,
121120
bottom: `${document.documentElement.clientHeight - convertedP1.y + divInfVerticalOffset}px`,
122121
});
123122
} else { // if you set body `position` as `relative`, `absolute`, things can get complicated
124123
const bodyRect = document.body.getBoundingClientRect();
125124
const bodyBorderLeft = parseFloat(bodyStyle.borderLeftWidth);
126125
const bodyBorderBottom = parseFloat(bodyStyle.borderBottomWidth);
127-
const bodyPaddingLeft = parseFloat(bodyStyle.paddingLeft);
128-
const bodyPaddingBottom = parseFloat(bodyStyle.paddingBottom);
129126
Object.assign(divInf.style, {
130-
left: `calc(${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft - bodyPaddingLeft}px - ${divInfWidth} / 2)`,
131-
bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom - bodyPaddingBottom + divInfVerticalOffset}px`,
127+
left: `${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft}px`,
128+
bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom + divInfVerticalOffset}px`,
132129
});
133130
}
134131
divInf.innerText = result.barcodeText;

0 commit comments

Comments
 (0)