$(function () {
$("lable").on("mousemove", function (event) {
let y = event.pageY - 40;
let x = event.pageX + 10;
var position = $(this).position();
let X = position.left.toFixed(0);
let Y = window.pageYOffset.toFixed(0);
if ($(this).find('div.tooltip').length == 0) {
let $new = $("<div/>", {
class: "tooltip",
text: $(this).attr("title")
});
$(this).append($new);
$new.animate({
opacity: 1
}, 1000);
} else {
tempY = y + 20
if (Y >= y) {
y = y + 50;
}
if (x>=X) {
x = x - 140;
}
if(x<=window.pageXOffset){
x = x +150;
}
$(this).find('div.tooltip').offset({
top: y,
left: x
});
}
$("#idiot").html("X = " + X + " , Y =" + Y + "<br/> x = " + x + ", y =" + y);
}).mouseout(function () {
$(this).find('div.tooltip').remove();
});
})