When I move the cursor inside of the media-slider-wrap the slider-paging follows the cursor, which is what I want. But when the mouse leaves the media-slider-wrap the slider-paging should disappear straight away, instead it keeps following the mouse.. If you move the cursor really slow out of the div then the slider-paging will basically show forever unless you move the cursor fast...
Any idea how to fix this?
Codepen for reference
$(document).ready(function(){
$(".slider").each(function () {
_this = $(this);
_this.mousemove(function(e){
var offset = _this.offset();
var rect = e.currentTarget.getBoundingClientRect();
var x = (e.clientX - rect.left);
var y = (e.clientY - rect.top);
$(this).find('.slider-paging').show();
$(this).find('.slider-paging').css("top", y).css("left", x);
});
_this.mouseleave(function(e){
$(this).find('.slider-paging').hide();
});
});
});
.media-slider-wrap {
width: fit-content;
}
.slider-paging {
position: absolute;
top: 0;
left: 0;
display:none;
}
.slider-image {
height: 500px;
width: 500px;
background: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="media-slider-wrap">
<div class="slider">
<div class="slider-image"></div>
<div class="slider-paging">1/4</div>
</div>
</section>