Avatar of rbanks303
rbanks303
 asked on

jQuery and CSS Popup In a Widget

Okay, I've got a tough one for you.  Whoever can solve this one is the master.

I have a widget that people install on their blog.  jQuery is installed with the widget.  The widget uses jquery to create a "hover popup" whenever someone moves their mouse over a persons picture.  

The HTML and Javascript I use to create the popup are listed in the code section.

Here's the problem: on this most blogs, the popup works great (move your mouse over the recent visitors widget):

http://tararustyhallejosh.blogspot.com 

However, on some blogs, the popup is displayed way too far to the right (move your mouse over the recent visitors widget):

http://blog.rustinbanks.com

I did some investigating, and it does look like that the CSS "left" and "top" properties are getting set correctly, just interpreted differently.  In the correct blog, the "left" value is the same as the .offset().left property of the popup.  This is what I would expect.  In the incorrect blog, the "left" value is the same as the .position().left property of the popup.  Both have absolute, not relative positioning.  

Whoever can figure this out will have awesome karma sent their way along with points!
<script type="text/javascript">
jQuery(document).ready(function() {
 
jQuery('.triggerpopup').hover(function() {
        var pos = jQuery(this).offset();
        var width = jQuery(this).width();
        jQuery(this).next("div").css({ "left": (pos.left + width) + "px", "top": pos.top + "px" });
        jQuery(this).next("div").stop(true, true).fadeIn("slow");
 
    }, function() { jQuery(this).next("div").fadeOut("fast"); });
 
 
});
</script>
 
<div class="triggerpopup">
A Picture And Some Text
</div>
<div class="popup" style="display:none; position:absolute;width:220px">
Some Text
</div>

Open in new window

jQueryWeb DevelopmentCSS

Avatar of undefined
Last Comment
rbanks303

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Silhouette

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rbanks303

ASKER
I cannot believe it, but it really works!  I thought position() was supposed to get the RELATIVE position to the parent object.  And when you set the "left" property of an "absolute" CSS positioned object you are setting "left" to the entire page.  How does this work?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23