0

I am making a tooltip. When hovering over the red lined areas, the tooltip should show up (which works fine).

enter image description here

The problem I have is that when increasing the distance to >80px between the icon and the tooltip, it stops working.

enter image description here

How could I make it work the same with increasing distance? My code is in Codepen using:

'moseover', 'mouseleave', adding classes, etc.

the space between them is a ::after that has a width, I think it could be increased at the same time and distance if the left of the tooltip is increased, but I don't know how to do it exactly.

enter image description here

TOOLTIP CODEPEN

This is my code in jquery...

    let keepOpen = false;
    $(document).on('mouseover', '.Hotspot__icon', function(){
      let id = $(this).data('tooltip');
      $(this).addClass('Hotspot__hover');
      $(this).parents('.Hotspot').addClass('Active__tooltip');

      if ($('#' + id).hasClass('Tooltip__right')) {
        $('#' + id).removeClass('Tooltip__left');
        $(this).removeClass('tl');
        $(this).addClass('tr');
      } 

      if ($('#' + id).hasClass('Tooltip__left')) {
        $('#' + id).removeClass('Tooltip__right');
        $(this).removeClass('tr');
        $(this).addClass('tl');
      }

      keepOpen = true;
      $('.Hotspot__content').css('display', 'none');
      $('#' + id).css('display', 'block');

    }).on('mouseleave','.Hotspot__icon',function(){ 
      let id = $(this).data('tooltip');
      $(this).removeClass('Hotspot__hover');
      $(this).parents('.Hotspot').removeClass('Active__tooltip');

      if ($('#' + id).hasClass('Tooltip__right')) {
        $('#' + id).removeClass('Tooltip__left');
        $(this).removeClass('tr');
        $(this).removeClass('tl');
      } 

      if ($('#' + id).hasClass('Tooltip__left')) {
        $('#' + id).removeClass('Tooltip__right');
        $(this).removeClass('tl');
        $(this).removeClass('tr');
      }

      keepOpen = false;
      if(!keepOpen){
        $('#' + id).css('display', 'none'); 
      }

    }).on('mouseover','.Hotspot__content',function(){
      let id = $(this).attr('id');
      $('[data-tooltip="'+id+'"]').addClass('Hotspot__hover');
      $('[data-tooltip="'+id+'"]').parents('.Hotspot').addClass('Active__tooltip');

      if ($(this).hasClass('Tooltip__right')) {
        $(this).removeClass('Tooltip__left');
        $('[data-tooltip="'+id+'"]').addClass('tr');
        $('[data-tooltip="'+id+'"]').removeClass('tl');
      } 

      if ($(this).hasClass('Tooltip__left')) {
        $(this).removeClass('Tooltip__left');
        $('[data-tooltip="'+id+'"]').addClass('tl');
        $('[data-tooltip="'+id+'"]').removeClass('tr');
      }

      keepOpen = true;
      $(this).css('display', 'block');

    }).on('mouseleave','.Hotspot__content',function(){
      let id = $(this).attr('id');
      $('[data-tooltip="'+id+'"]').removeClass('Hotspot__hover');
      $('[data-tooltip="'+id+'"]').parents('.Hotspot').removeClass('Active__tooltip');


      if ($(this).hasClass('Tooltip__right')) {
        $(this).removeClass('Tooltip__left');                
        $('[data-tooltip="'+id+'"]').removeClass('tr');
        $('[data-tooltip="'+id+'"]').removeClass('tl');
      } 

      if ($(this).hasClass('Tooltip__left')) {
        $(this).removeClass('Tooltip__right');
        $('[data-tooltip="'+id+'"]').removeClass('tl');
        $('[data-tooltip="'+id+'"]').removeClass('tr');
      }

      keepOpen = false;
      $(this).css('display', 'none');
    });

Please help!

3
  • Please include a small re-producible sample of your problem here in code instead of linking to a codepen. Commented May 10, 2021 at 22:12
  • @Dominik thanks for your answer, the code I am using does not work well here Commented May 10, 2021 at 22:16
  • 1
    Please create a Code Snippet of your code so, Anyone can check your code and can help. Commented May 11, 2021 at 7:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.