Ok, so I want to have the the div '.prodimg' follow the mouse pos. And this works, except it's being positioned relative to the left pos of #wrapper that is a parent div of '.details' and '.prodimg'. Why is this happening? Any suggestions to fix it or alternative methods of tracking the mouse?
'.prodimg' top position was relative to the #wrapper top, then I changed it to padding-top and .prodimg was corrected. This has something to do with my problem, but I cant find a similar solution for the left position. Ideally I wouldn't have to change the wrapper to get pageX and pageY to relate to the full window.
I've tried with with the '#wrapper' position:relative and nothing changed. '.details' MUST be relative so that it can float inline. I have the jquery entered beneath my wrapper. Ive tried using 'document' in place of 'window'. Not sure if any of this has to do with it... Please help! I've lost almost 3 hours on this problem :/
here is my fiddle: http://jsfiddle.net/vg2zL/
$(document).ready(function() {
var mouseX;
var mouseY;
$(window).mousemove( function(e) {
mouseX = e.pageX;
mouseY = e.pageY;
});
$(".details").hover(
function () {
$(this).children(".prodimg").css("visibility","visible");
$(window).bind('mousemove', function(e){
$(".details").children(".prodimg").css({'top':mouseY,'left':mouseX});
});
},
function () {
$(".prodimg").css("visibility","hidden");
});
});
and heres my styles
#wrapper {
width: 700px;
padding-top: 130px;
position: absolute;
left:50%;
margin-left: -351px;
font-size: 30px;
font-family: 'cmu_serifroman';
}
.details {
text-align:center;
width:200px;
display:inline-block;
line-height:40px;
margin-right:50px;
cursor:pointer;
}
.prodimg {
visibility:hidden;
position:absolute;
z-index:-1;
}