Skip to content

Commit a39dfb3

Browse files
author
Mihir
committed
Fix original price popup
1 parent 531c4b4 commit a39dfb3

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/main.css

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#strict-mode,
9999
.budget-mode {
100100
position: relative !important;
101+
overflow: visible !important;
101102
}
102103

103104
#strict-mode::after {
@@ -115,10 +116,7 @@
115116
}
116117

117118
.budget-price {
118-
position: absolute !important;
119-
bottom: 100% !important;
120-
left: 50% !important;
121-
transform: translateX(-50%) !important;
119+
position: fixed !important;
122120
background-color: #1a1a1a !important;
123121
color: #ffffff !important;
124122
padding: 6px 10px !important;
@@ -130,14 +128,9 @@
130128
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
131129
opacity: 0 !important;
132130
visibility: hidden !important;
133-
transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease !important;
134-
transform: translateX(-50%) translateY(-4px) !important;
135-
margin-bottom: 8px !important;
131+
transition: opacity 0.15s ease, visibility 0.15s ease !important;
136132
font-weight: 500 !important;
137133
font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, sans-serif !important;
138-
/* Prevent clipping by parent containers */
139-
contain: none !important;
140-
will-change: opacity, visibility, transform !important;
141134
}
142135

143136
.budget-price::before {
@@ -160,7 +153,6 @@
160153
.budget-mode:hover .budget-price {
161154
opacity: 1 !important;
162155
visibility: visible !important;
163-
transform: translateX(-50%) translateY(0) !important;
164156
}
165157

166158
@media (prefers-color-scheme: dark) {

src/main.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,32 @@ function createHiddenEarlierPriceElement(earlierPrice, priceElement) {
164164
span.classList.add('budget-price');
165165
span.innerText = earlierPrice;
166166
priceElement.appendChild(span);
167-
// Tooltip is now controlled via CSS hover on #strict-mode
167+
168+
// Position tooltip on hover using fixed positioning
169+
const positionTooltip = () => {
170+
const rect = priceElement.getBoundingClientRect();
171+
const tooltipRect = span.getBoundingClientRect();
172+
173+
// Position above the element, centered
174+
const left = rect.left + (rect.width / 2) - (tooltipRect.width / 2);
175+
const top = rect.top - tooltipRect.height - 8; // 8px gap
176+
177+
span.style.left = `${left}px`;
178+
span.style.top = `${top}px`;
179+
};
180+
181+
// Update position on hover
182+
priceElement.addEventListener('mouseenter', positionTooltip);
183+
184+
// Also update on scroll to keep it positioned correctly
185+
let scrollTimeout;
186+
const handleScroll = () => {
187+
if (priceElement.matches(':hover')) {
188+
clearTimeout(scrollTimeout);
189+
scrollTimeout = setTimeout(positionTooltip, 10);
190+
}
191+
};
192+
window.addEventListener('scroll', handleScroll, true);
168193
}
169194

170195
function addZerosToNumber(actualPrice, strictlyAdjustedPrice) {
@@ -332,11 +357,11 @@ function append(elementInfo, element, productPrice, settings, isPriceRange) {
332357
if (settings.hoverMode) {
333358
// Hover Mode Attributes
334359
badge.style.display = 'none';
335-
element.addEventListener('mouseover', function handleMouseOver() {
360+
desiredElement.addEventListener('mouseover', function handleMouseOver() {
336361
badge.style.display = 'inline-flex';
337362
});
338363
desiredElement.setAttribute("title", `It will take you ${getTimeTakenToEarn(productPrice, settings.salary)} to earn ${productPrice}`);
339-
element.addEventListener('mouseout', function handleMouseOut() {
364+
desiredElement.addEventListener('mouseout', function handleMouseOut() {
340365
badge.style.display = 'none';
341366
});
342367
} else if (!isPriceRange) {

0 commit comments

Comments
 (0)