Keep tooltip inside of parent container

蹲街弑〆低调 提交于 2020-01-16 05:25:25

问题


I am using jQuery UI Tooltip in a web app. By default the position of the tooltip is bottom-left of the 'tool-tipped element'. However, when the tooltip will not fit in the browser window, it switches to bottom right.

This behavior is great, however rather than determining whether to position the tooltip bottom right or bottom left based on the width of the browser window, I would like to determine this based on the width of a parent container, so that the tooltips do not display outside of an area that I determine.

Please note I am aware of how to control the position manually with the API, I am looking for away to control the logic of the positioning globally.

$(function() {
    $( '#bodyInner' ).tooltip();
});

This is so far I have done.


回答1:


You can achieve anything related to positioning of tooltip using the position option in the jQuery UI Tooltip. The jQuery UI Position option contain many further options such as my, at etc. Once such option is within. This can be used to limit the position of an element within another.

Here, the tooltips position can be contained within the parent element simply by initializing the tooltip as follows.

$( '#bodyInner' ).tooltip({
    position:{ within: "#bodyInner"}
});

Here is the Demo.



来源:https://stackoverflow.com/questions/21488926/keep-tooltip-inside-of-parent-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!