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

Home Forums JavaScript change tooltip position

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

    Here is my code that implements tooltips in my website:
    var changeTooltipPosition = function(event) {
    var tooltipX = event.pageX – 8;
    var tooltipY = event.pageY + 8;
    jQuery(‘div.tooltip’).css({top: tooltipY, left: tooltipX,’z-index’: ‘120000’});
    This works fine and displays the tooltip as a popup window bellow and to the right of the cursor while hoovering the button.
    I’d like to modify the code so that the tooltip will appear just above the cursor(and the button, no change to the x dimension).
    Is it possible and how?
    I. Sher


    If you don’t want to change the x value at all then just remove that from the code above. Am I understanding correctly? Have you tried anything? Did it work? What happened when you tried it?

    Remove this

    left: tooltipX

    from the jQuery CSS call. You can then remove the line that sets the tooltipX variable as well.


    Dear nkrisc
    The x dimension is right so no need to modify.
    What I really need is to assign the tooltipY the current value minus the value of the tooltip height(which I don’t know how to express it in the code).
    I. Sher


    Ok I solved the problem
    I added the following lines before the final line
    var tooltipHeight = jQuery(‘div.tooltip’).height();
    var tooltipY = event.pageY – tooltipHeight;
    I. Sher

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