jQuery positionオプションを使用してツールチップの表示位置を変える
環境
Google Chrome 105.0.5195.127
Windows 10 Home 64bit
jquery 3.6.1
構文
$(document).tooltip({
position:{
my:"left+40 top",//ツールチップの位置を表示
at:"right top", //ツールチップを表示する時に基準の位置を表示
collision:"flipfit" //ツールチップがウィンドウの幅を超えた時の挙動
positionオプションを設定してツールチップの表示位置を変えます。
使用例
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function(){
$(document).tooltip({
position:{
my:"left+40 top",
at:"right top",
collision:"flipfit"
}
}
);
});
</script>
</head>
<body>
<p><span title="東京品川区">東京</span></p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function(){
$(document).tooltip({
position:{
my:"left+40 top",
at:"right top",
collision:"flipfit"
}
}
);
});
</script>
</head>
<body>
<p><span title="東京品川区">東京</span></p>
</body>
</html>
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <script> $(function(){ $(document).tooltip({ position:{ my:"left+40 top", at:"right top", collision:"flipfit" } } ); }); </script> </head> <body> <p><span title="東京品川区">東京</span></p> </body> </html>
実行結果
文字「東京」の文字の上にカーソルを当てるとツールチップを文字の右上に表示させます。