@@ -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
170195function 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