2012-07-20 34 views
3

我想我的居中提示泡沫,但沒有成功:(我猜測,解決方案很簡單,但我不能做到這一點的人可以幫我THX !! Fiddle here
我的代碼:?如何以我的工具提示爲中心? 。

$(document).ready(function(){ 
$(".menu .a").hover(function() { 
var checkWidth = $(this).outerWidth() - $(this).outerWidth()/2; 
    $(this).next("em").css({left:checkWidth}).animate({opacity: "show"}, "slow"); 
    }, function() { 
    $(this).next("em").animate({opacity: "hide"}, "fast"); 
    }); 
}); 

回答

3

This Fiddle應該爲你工作,你必須要考慮的工具提示本身的寬度

var checkWidth = $(this).outerWidth() - $(this).outerWidth()/2 - $(this).next("em").outerWidth()/2; 
+0

謝謝您的幫助,我很抱歉,因爲這麼啞! – 2012-07-20 13:56:09

+1

愚蠢是花費數小時試圖解決這個問題時,你可以引導到正確的答案。我以前去過那裏 - 當你沒有馬上看到它時,可能會感到沮喪。 – SliverNinja 2012-07-20 13:56:56

0

如何:。

.menu li em { 
white-space:nowrap; 
background-color:red; 
position: absolute; 
margin-top:-100px; 
margin-left: -50px; /* I added just this line */ 
text-align: center; 
padding: 20px; 
font:12px helvetica, arial, sans-serif; 
display:none; 
}