I am looking to create a tooltip box that appears when hovering over an element, and I want the tooltip to only disappear when the user's mouse exits a specific custom hover area outlined by a vector graphic.
My current implementation is working, but the hover area is causing click events to be blocked from reaching the tooltip, as illustrated below.
$(document).ready(function() {
$("#hover-me").mouseenter(function(e) {
$("#mouse-box").css("visibility", "visible");
$("#tooltip").show();
});
$("#mouse-box").mouseleave(function(e) {
$("#mouse-box").css("visibility", "hidden");
$("#tooltip").hide();
});
});
#tooltip {
position: absolute;
top: 20px;
display: none;
height: 60px;
}
#hover-me {
position: absolute;
top: 40px;
left: 140px;
}
svg {
position: absolute;
left: 0;
width: 210px;
height: 83px;
opacity: 0.03;
pointer-events: none;
}
svg clipPath rect:first-child {
width: 90px;
height: 100%;
x: 0;
y: 0;
}
svg clipPath rect:last-child {
width: 130px;
height: 35px;
x: 90px;
y: 25px;
}
#mouse-box {
fill: red;
visibility: hidden;
width: 100%;
height: 100%;
pointer-events: visible;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="tooltip">Can't click</button>
<div id="hover-me">Hover me</div>
<svg>
<defs>
<clipPath id="clip">
<rect/><rect/>
</clipPath>
</defs>
<rect id="mouse-box" clip-path="url(#clip)"/>
</svg>