jQuery tooltip follow mouse

前端 未结 1 2052
天命终不由人
天命终不由人 2021-01-28 18:14

I\'ve been using this script http://jqueryfordesigners.com/coda-popup-bubbles/

and trying to use this fix to position the bubble according to where the user\'s mouse is

1条回答
  •  时光取名叫无心
    2021-01-28 18:37

    after the bubble is shown you need to set some function say timeout to update the bubble position according to mouse position.

    function:

    var x,y;//to track mouse positon
    function UpdatePosition(){      
       $(ID_OF_BUBBLE).css({left:x+"px",top:y+"px"});         
       setTimeout("UpdatePosition()",100);
    }
    

    you may insert it here:

    if (beingShown || shown) {
     //SETUP timeout to a function which updates bubble's position
     setTimeout("UpdatePosition()",100);
    return;
    

    add mouse move hook to get position:

    $(document).ready(function(){
        $().mousemove(function(e){
        x=e.pageX ;
        y=e.pageY;
        });
       .......
    });
    

    PS:- you may have to tweak position mode of the bubble

    0 讨论(0)
提交回复
热议问题