Now I want to save this popup when the mouse exits the tag and continues this popup.
MouseEvent.relatedTarget, , .
mouseleave, , . relateTarget, , . , tag_info, .
jquery, jquery, :
$(e.relateTarget)
tag_info
, !
$.fn.right = function() {
return $(document).width() - (this.offset().left + this.outerWidth());
}
$(document).ready(function() {
$('a').bind('mouseenter', function() {
var self = $(this);
var iid = this.iid = setTimeout(function() {
var tag_name = self.text(),
top = self.position().top + self.outerHeight(true),
right = self.right();
$('body').append("<div class='tag_info'>Some explanations about " + tag_name + "</div>");
var tagInfo = $(".tag_info");
tagInfo.css({
top: top + "px",
right: right + "px"
}).fadeIn(200);
tagInfo.bind('mouseleave', function (e) {
console.log('mouse left tag info');
if (iid) {
clearTimeout(iid)
tagInfo.remove();
}
});
}, 525);
}).bind('mouseleave', function(e) {
if (e.relatedTarget && e.relatedTarget.classList.contains('tag_info')) {
console.log('mouse left onto the tag_info');
} else {
console.log('mouse left onto something else');
if (this.iid) {
clearTimeout(this.iid)
$('.tag_info').remove();
}
}
});
});
body {
padding: 20px;
direction: rtl;
}
a {
color: #3e6d8e !important;
background-color: #E1ECF4;
padding: 2px 5px;
}
.tag_info {
position: absolute;
width: 130px;
height: 100px;
display: none;
background-color: black;
color: white;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a>long-length-tag</a>
<a>tag</a>