The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Guide for created a tooltip simple?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #35009

    Why in following code(example) tooltip box come out from page, how can it fix as automatic(dynamic) with page that not come out from page?

    Demo: (i mane is about how that mouse over on it display toltip box out page) SEE image:

    $('li a').hover(function() {

    var title = $(this).next('.tooltip').html();
    var offset = $(this).offset();

    $tooltip = $('

    var delay = setTimeout(function() {

    var width = $tooltip.outerWidth();

    var p_top =;
    var p_left = offset.left - width;
    $tooltip.css({top: p_top, left: p_left}).fadeIn(180);


    $(this).data('delay', delay);
    $(this).data('tooltip', $tooltip);

    },function() {

    delay = $(this).data('delay');
    $tooltip = $(this).data('tooltip');


    Hi binboy!

    All you need to do is check if the tooltip height plus the offset height is more than the window height (meaning the tooltip will go off screen). I added these two lines under the “p_top” defintion

    var tt_ht = $tooltip.height();
    p_top = (p_top + tt_ht > $('window').height()) ? p_top - tt_ht : p_top;

    And updated the demo.

    It should get the correct tooltip height since jQuery reveals the tooltip quickly (you shouldn’t be able to see it) to get the height, but I’m not sure it’s 100% correct since the about tooltip seems to shift up as well.


    Now see it: it must dynamic for set with page: what do i do?

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.