Skip to content

Commit a0efe18

Browse files
authored
transform: translateX(-50%)
1 parent 5f8b8ca commit a0efe18

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 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: '';
@@ -111,24 +113,20 @@
111113
divInf = document.createElement("div");
112114
divInf.className = 'bubble-box';
113115
// define width of the bubble box
114-
const divInfWidth = "20rem";
115-
divInf.style.width = divInfWidth;
116116
const divInfVerticalOffset = 4; //px
117117
const bodyStyle = getComputedStyle(document.body);
118118
if (bodyStyle.position === "static") {
119119
Object.assign(divInf.style, {
120-
left: `calc(${(convertedP1.x + convertedP2.x) / 2}px - ${divInfWidth} / 2)`,
120+
left: `${(convertedP1.x + convertedP2.x) / 2}px`,
121121
bottom: `${document.documentElement.clientHeight - convertedP1.y + divInfVerticalOffset}px`,
122122
});
123123
} else { // if you set body `position` as `relative`, `absolute`, things can get complicated
124124
const bodyRect = document.body.getBoundingClientRect();
125125
const bodyBorderLeft = parseFloat(bodyStyle.borderLeftWidth);
126126
const bodyBorderBottom = parseFloat(bodyStyle.borderBottomWidth);
127-
const bodyPaddingLeft = parseFloat(bodyStyle.paddingLeft);
128-
const bodyPaddingBottom = parseFloat(bodyStyle.paddingBottom);
129127
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`,
128+
left: `${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft}px`,
129+
bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom + divInfVerticalOffset}px`,
132130
});
133131
}
134132
divInf.innerText = result.barcodeText;

0 commit comments

Comments
 (0)