Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:工具提示定位_Jquery_Css - Fatal编程技术网

jQuery:工具提示定位

jQuery:工具提示定位,jquery,css,Jquery,Css,我试图找出如何正确地将工具提示居中放置在链接下(因此它不会与链接对齐) 我还试图弄明白为什么我的工具提示没有消失 这里: $('a.tooltip').hover(function() { var title = $(this).attr('title'); var offset=$(this).offset(); var width=$(this).outerWidth(); var height=$(this).outerHeight(); $cont

我试图找出如何正确地将工具提示居中放置在链接下(因此它不会与链接对齐)

我还试图弄明白为什么我的工具提示没有消失

这里:

$('a.tooltip').hover(function() {
    var title = $(this).attr('title');
    var offset=$(this).offset();
    var width=$(this).outerWidth();
    var height=$(this).outerHeight();
    $content=$('<div class="tooltip">' + title + '</div>').fadeIn();
    $(this).append($content);
    var middle = offset.left+(width-$content.outerWidth())/2;
    // middle = Math.max(offset.left,offset.left+(width-$content.outerWidth())/2 );
    $content.offset({ top: offset.top+height, left: middle });
    $('div.tooltip').hover(function() {
        $(this).fadeOut('fast');            
    });
}, function() {
    $(this).find('div').fadeOut('fast');
});
$('a.tooltip')。悬停(函数(){
var title=$(this.attr('title');
var offset=$(this.offset();
var width=$(this.outerWidth();
var height=$(this.outerHeight();
$content=$(''+标题+'').fadeIn();
$(this).append($content);
var middle=offset.left+(宽度-$content.outerWidth())/2;
//middle=Math.max(offset.left,offset.left+(宽度-$content.outerWidth())/2);
$content.offset({top:offset.top+height,left:middle});
$('div.tooltip')。悬停(函数(){
$(this.fadeOut('fast');
});
},函数(){
$(this.find('div').fadeOut('fast');
});
​ 您可以使代码更具可读性,但想法就在这里;)


[编辑]代码更改,即使文本太长,也必须居中。(我看错了问题)

我更新了它,这就是你想要的吗?这将使短工具提示居中,但当您将鼠标悬停在带有较长工具提示的“测试”上时,它不会使其居中。想法?哦,对不起,这是功能性的!读错了!我更改代码;)
$('a.tooltip').hover(function() {
    var title = $(this).attr('title');
    var offset=$(this).offset();
    var width=$(this).outerWidth();
    var height=$(this).outerHeight();
    $content=$('<div class="tooltip">' + title + '</div>').fadeIn();
    $(this).append($content);
    var middle = offset.left+(width-$content.outerWidth())/2;
    // middle = Math.max(offset.left,offset.left+(width-$content.outerWidth())/2 );
    $content.offset({ top: offset.top+height, left: middle });
    $('div.tooltip').hover(function() {
        $(this).fadeOut('fast');            
    });
}, function() {
    $(this).find('div').fadeOut('fast');
});