question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatic placement of tooltips/popovers

See original GitHub issue

Here’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:closed
  • Created 12 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mindplay-dkcommented, Jun 26, 2013

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. Placement any could also be used as an alias for top right bottom left.

This behavior would also be backwards compatible, since specifying only one position with no alternatives would work the same as before.

0reactions
Michealzcommented, Jan 27, 2016

@quasiperfect: That work for me. thanks so much

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found