0

I created a callout as follows. As you can see, the callout not being hidden when I hover out from the i icon. Do I use the wrong event? I tried switching mouseover and mouseleave but the callout looks blinking.

Any help appreciated! :)

$(".text-with-tooltip i").hover(function() {
  $(".callout-tooltip").show();
});
.text-with-tooltip {
  font-size: 13px; 
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.text-with-tooltip i {
  margin-left: 4px; 
  font-size: 11px;
}

.callout.callout-tooltip {
  height: 60px;
  width: 200px;
  float: left;
}

.callout.callout-tooltip {
  background-color: rgba(0,0,0,0.8);
  color: #ccc;
  padding: 8px;
  padding-bottom: 4px;
  border-radius: 3px;
  min-height: 50px;
  border: 1px solid #333;
  text-shadow: 0 0 1px #000;
  text-align: center;
  font-size: 12px;
  position: absolute;
  top: 28%;
  left: 50%;
  transform: translate(-50%, -28%);
  display: none;
}

.callout.callout-tooltip::before {
  content: "";
  width: 0px;
  height: 0px;
  border: 0.8em solid transparent;
  position: absolute;
}

.callout.callout-tooltip.top::before {
  left: 45%;
  bottom: -20px;
  border-top: 10px solid rgba(0,0,0,0.8);
}

.tooltip-wrapper {
  height: 400px;
  width: 100%;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">

<div class="tooltip-wrapper">
  <div class="text-with-tooltip">Manual<i class="fas fa-info-circle"></i></div>
</div>

<div class="callout top callout-tooltip">You must enter the request number every time you add new entry on Reimbursement Entry</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Dolorosa
  • 573
  • 3
  • 10
  • 29
  • 1
    **1.** You hover over the icon. `hover` is triggered. **2.** The popup appears *in front of the icon*. **3.** Because the icon is blocked, `hover` is interrupted and the popup disappears. **4.** The icon is no longer covered. **Rinse and repeat.**. This all happens in the span of milliseconds, thus your flashing/flickering. Simply repositioning the tooltip so that it doesn't cover your `i` icon should solve the problem (assuming you add the second `mouseout` parameter of `.hover(...)` back in). – Tyler Roper May 29 '18 at 20:36
  • @TylerRoper thank you for your explanation. I keep my function and try repositioning the callout, but it still doesn't work.. – Dolorosa May 29 '18 at 20:42
  • 1
    Can you edit your question to include that example instead? We'd rather have code that reproduces the issue than code without, as it's much easier to debug. – Tyler Roper May 29 '18 at 20:43

2 Answers2

0

If you're willing to use the function with an ID instead of the CSS class, you can try this.

$("#yourID").hover(function() {
    $(this).css('cursor','pointer').attr('title', 'This is a hover text.');
}, function() {
    $(this).css('cursor','auto');
});

I would recommend using an ID instead of a class because IDs have a higher importance level and this might save you some headache down the road if you have a bunch of elements on the page with the same class that you want to treat differently.

Justin R.
  • 489
  • 1
  • 5
  • 12
  • This does not solve any of OPs issues. OP has obviously gone through a few lengths to have a custom-styled tooltip, I'd imagine this isn't a useful alternative. – Tyler Roper May 29 '18 at 20:50
0

If you add this to your JS:

$(".text-with-tooltip i").mouseleave(function() {
  $(".callout-tooltip").hide();
});

You will be good.

Fiddle example: https://jsfiddle.net/rdenu53a/

Dylan
  • 1,681
  • 11
  • 16
  • I would test that before being so sure - if you make your answer a snippet with OPs code, this causes the same flickering that OP described. – Tyler Roper May 29 '18 at 20:49
  • @TylerRoper well... I tried pairing `mousover` and `mouseleave` since I thought they were commonly paired. I don't know that I can pair `hover` and `mouseleave` tho ;) ;) – Dolorosa May 29 '18 at 20:54
  • @Rosiana `hover` is a shorthand container for `mouseover` and `mouseleave` - this means that `hover` and `mouseover` are *identical*. If you edit the snippet in your question and add this to it, it will flicker all the same. – Tyler Roper May 29 '18 at 20:55