jquery - javascript tooltip follows cursor position -


i'm trying make tooltip image appear above cursor when hovering on thumbnail, i'm working developer's code , having trouble figuring out.

i've created simplified version of code on website can found below, or on jsfiddle: http://jsfiddle.net/justinwebpro/kf8lqn5v/5/

or live site issue i'm trying correct here: https://www.mychicnest.com/productdetails.asp?productcode=503

i'm trying use method .mousemove() make follow mouse position rather being static @ top of page i'm doing wrong. ideally factor in offset of cursor position, getting work @ comes first!

html

<div id="swatch">     <div id="panel">           <img src="large.jpg" id="large-image" />     </div>     <div id="thumbs">         <img src="1.jpg" />         <img src="2.jpg" />         <img src="3.jpg" />     </div> </div> 

css

#swatch { position: relative; }  #panel {         position: absolute;         top: -115px;         left: 115px; } 

javascript

function swthumbeffect(){     $('#panel').css('visibility','hidden');      $('#thumbs img').mouseover(function(){         $('#largeimage').attr('src',$(this).attr('src'));         $('#panel').css('visibility','visible');     });     $('#thumbs img').mouseout(function(){         $('#panel').css('visibility','hidden');     }); }   // came swatch follow cursor isn't working hoped. ideally factor in offset of cursor, getting work comes first. $('#thumbs img').mousemove(function( event ) {     var mousepositionx = event.pagex;     var mousepositiony = event.pagey;     log(mousepositionx);     log(mousepositiony);     $('#panel').css('left', mousepositionx);     $('#panel').css('right', mousepositiony); }); 

thanks in advance!

you have couple of problems current function, should work minor modifications. first problem: you're setting right css property clienty. should top:

     $('#panel').css('top', mousepositiony); 

then need consider position of #panel parent position correctly. can way:

     //you should avoid showing panel right under mouse, because it'll mess      //with mouseout event since #thumb hidden.      //you can add 20 pixels position example.        var mousepositionx = event.pagex-$('#panel').parent().offset().left+20;      var mousepositiony = event.pagey-$('#panel').parent().offset().top+20; 

and maybe should try put mousemove call in swthumbeffect function other mouseevents call.

and should work properly.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -