そのため、jqueryでホバーツールチップを配置する際に少し問題があります。親divのcssの「position」属性が「relative」に設定されている場合、ツールチップは画面の左上に飛んでいきます。position属性を削除すると、すべてが正常に機能し、ツールチップが返されます。
私はjQueryやcssのポジショニングルールをあまりよく理解していないので、質問は次のとおりです。
- position:relativeがjQueryツールチップの配置を台無しにするのはなぜですか?
- position:relativeが必要だった場合(そして必要ない場合)、問題を解決するために何ができますか?
関連するコードは次のとおりです。
$("yay").hover(
function(){
// .position() uses position relative to the offset parent,
var pos = $(this).position();
// .outerWidth() takes into account border and padding.
var width = $(this).outerWidth();
var messageToLoad = dumpArray[$(this).attr('class')];
$(messageToLoad).css({
left: (pos.left + width) + "px",
top: pos.top + "px",
position: "absolute",
"visibility":"visible",
"display":"inline"
});
},
そして、(問題のある)cssは次のとおりです。
.content {
margin: 0 0 0 35px;
position:relative;
}
htmlは次のとおりです。
...
<tr class="PostOdd">
<td>
<div class="contents">
<div class="content">
<p> Brand new post goes here</p>
<p class="postDate">June 15, 2012, 4:02 a.m.</p>
<p class="options">
<a href="/comments/1/1">
<img class="yay" src="/static_files/chat-icon.png">
</a>
</p>
</div>
</div>
...
アップデート:
a。私はjqueryのみを使用しており、他のJavaプラグインはまったく使用していません
b。cssファイルの親に起因する「位置」属性を削除すると、すべてが正常に機能します。実は削除したので、好奇心ほど問題にはなりません。私は別のセクションに取り組んでいます-そのセクションを終えるまでに答えが得られない場合は、jfiddleデモを作成します