本帖最后由 vanshion 于 2010-12-09 15:00:08 编辑

解决方案 »

  1.   

            tip = $(this).find('.tip'); $(".tip_trigger").hover(function(){
    前面加个
    var tip
      

  2.   

    我找了一下  这个TIP真的没有定义过,你这段代码是不是从哪里copy过来的哦      你仔细找一下原来的代码  按我看是要在方法内定义一个tip的
    如果不行  那就定义一个全局tip试试。再不行。你只能去找原来的代码,你肯定漏了什么
      

  3.   


    我想应该不是吧 tip = $(this).find('.tip'); tip是这样取出来的, 
    var tipWidth = tip.width(); //Find width of tooltip
    var tipHeight = tip.height(); //Find height of tooltip
    提示为定义应该是在这里报错
      

  4.   

    改成这样试试呢
    <script type="text/javascript">
    $(document).ready(function() {
        //Tooltips
        var tip = $(this).find('.tip');
        $(".tip_trigger").hover(function(){
            tip.show(); //Show tooltip
        }, function() {
            tip.hide(); //Hide tooltip          
        }).mousemove(function(e) {
            var mousex = e.pageX + 20; //Get X coodrinates
            var mousey = e.pageY + 20; //Get Y coordinates
            var tipWidth = tip.width(); //Find width of tooltip
            var tipHeight = tip.height(); //Find height of tooltip
            
            //Distance of element from the right edge of viewport
            var tipVisX = $(window).width() - (mousex + tipWidth);
            //Distance of element from the bottom of viewport
            var tipVisY = $(window).height() - (mousey + tipHeight);
              
            if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
                mousex = e.pageX - tipWidth - 20;
            } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
                mousey = e.pageY - tipHeight - 20;
            } 
            tip.css({  top: mousey, left: mousex });
        });
    });</script>
      

  5.   


    其他都是浮云啊!如microwindlab所述,把
    $(".tip_trigger").hover(function(){
    tip = $(this).find('.tip');
    tip.show(); //Show tooltip
    }
    改成
        var tip = $(this).find('.tip');
        $(".tip_trigger").hover(function(){
            tip.show(); //Show tooltip
        }对microwindlab表示万分感谢
      

  6.   

    不过microwindlab的改法会出现一个问题,同时有两处调用这个JS的话,就会出现同样的内容,就算两个地方内容不一样,也会被重复。
    于是我改成如下
    不知道这样合理不合理
    $(document).ready(function() {
    //Tooltips
    var tip = $(this);
    $(".tip_trigger").hover(function(){
    tip = $(this).find('.tip');
    tip.show(); //Show tooltip
    }, function() {
    tip.hide(); //Hide tooltip   
    }).mousemove(function(e) {
    var mousex = e.pageX + 20; //Get X coodrinates
    var mousey = e.pageY -10; //Get Y coordinates
    var tipWidth = tip.width(); //Find width of tooltip
    var tipHeight = tip.height(); //Find height of tooltip

    //Distance of element from the right edge of viewport
    var tipVisX = $(window).width() - (mousex + tipWidth);
    //Distance of element from the bottom of viewport
    var tipVisY = $(window).height() - (mousey + tipHeight);
      
    if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
    mousex = e.pageX - tipWidth - 20;
    } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
    mousey = e.pageY - tipHeight - 20;

    tip.css({  top: mousey, left: mousex });
    });
    });