CSS
変更点:
#features_icons li span {
top:0; /* ///added to fix in chrome ///*/
left:0;/* ///added to fix in chrome///*/
white-space:nowrap;/* ///added this line/// */
}
#features_icons li {
position:relative; /* ///added this line/// */
}
そして、追加したばかりのjquery内に:outerWidth(true)
正しい寸法を取得するには:
spanW = ($(this).next("span").outerWidth(true) / 2) - ($(this).outerWidth(true) / 2);
また、試すこともできます: すべての<SPAN>
要素
を別の方法で削除します:
どのような場合でも、アイコンには alt 属性が必要です... では、各画像に SPAN テキストを付与しない理由はありません: (どの CMS エディターでも、画像にalt. 説明テキストを追加できます。)
<img alt="Air Conditioning" src="http:conditioning.png" />
したがって、すべてのスパンを削除して、<body>
タグの後にこれを追加できます。
<div id="tooltip"></div>
私のスクリプトを使用します:
$("ul#features_icons li img").hover(function() {
var altText = $(this).attr('alt');
var thisW2 = $(this).outerWidth(true) / 2;
var thisPosL = $(this).offset().left + thisW2;
var thisPosT = $(this).offset().top;
$('#tooltip').text(altText);
var toolW2 = $('#tooltip').outerWidth(true) / 2; // after it's filled with text
$('#tooltip').stop(1).fadeTo(200,1).css({left: (thisPosL-toolW2) , top:thisPosT});
}, function() {
$('#tooltip').fadeTo(100,0,function(){
$(this).hide();
});
});
- アイコンの位置を計算します
alt
テキストをつかむ
#tooltip
テキストで埋める
- ツールチップの幅を取得する
- 位置
#tooltip
- そしてそれを見せてください!
PS: CSS で名前を変更しました:#features_icons li span {
に#tooltip{