Automatic placement of tooltips/popovers
See original GitHub issueHere’s what I’m doing atm.
var getPlacement = function($el) {
var offset = $el.offset(),
top = offset.top,
left = offset.left,
height = $(document).outerHeight(),
width = $(document).outerWidth(),
vert = 0.5 * height - top,
vertPlacement = vert > 0 ? 'bottom' : 'top',
horiz = 0.5 * width - left,
horizPlacement = horiz > 0 ? 'right' : 'left',
placement = Math.abs(horiz) > Math.abs(vert) ? horizPlacement : vertPlacement;
return placement
};
and
$el.popover({
placement: getPlacement($el),
trigger: 'manual',
html: true,
title: function() {
return 'Laddar...';
},
content: function() {
return 'Laddar...';
}
});
Issue Analytics
- State:
- Created 12 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Tooltips and popovers - KVision Guide - GitBook
Every component in KVision can display a tooltip and a popover, both are based on ... the placement and the list of trigger...
Read more >Popper - Tooltip & Popover Positioning Engine
Places your tooltip or popover relative to the reference taking into account their sizes, and positions its arrow centered to the reference. ·...
Read more >Position Tooltips and Popovers Using Popper.js - YouTube
Popper.js can be used to place the tooltips and other form of popovers in a variety of different ways. It also has the...
Read more >Popovers - Bootstrap
How to position the popover - auto | top | bottom | left | right. When auto is specified, it will dynamically reorient...
Read more >Bootstrap 4 tooltip/popover using auto placement as a fallback ...
i.e. if your placement is only 'left' but there isn't room, BS4/popper already moves it to make sure it displays. So I guess...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
PS: a better way to do this, would be to allow for alternative placements.
For design reasons, your tooltips may have an ideal placement, and one or more alternative fall-back placements - for example, you may have a fixed sidebar on the right, so you know there will always be enough space for the tooltip on the right.
Allowing multiple alternative positions, separated by spaces, in order of preference, such as:
placement: 'top right'
which would place the tooltip on top if possible, otherwise to the right. Placementany
could also be used as an alias fortop right bottom left
.This behavior would also be backwards compatible, since specifying only one position with no alternatives would work the same as before.
@quasiperfect: That work for me. thanks so much