I would like to load data(via ajax) in a tooltip when the mouse is over a specific area. The problem is that the ajax call is made as long as my mouse is on that area. Is there any way, that I could make onmouseover (ajax call) efect happen just once? Here is the code:
$.post('calendar/event-details', {'eventId' :event.id},
function (data){
this.top = (ui.clientY + 15); this.left = (ui.clientX - 230);
$('body').append( '<div id="vtip">' + data + '</div>' );
$('div#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
$('div#vtip').css("position","absolute");
$('div#vtip').css("z-index", "+99");
})
Definition and Usage The onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children. Tip: This event is often used together with the onmouseout event, which occurs when a user moves the mouse pointer out of an element.
The mouseover() method triggers the mouseover event, or attaches a function to run when a mouseover event occurs. Note: Unlike the mouseenter event, the mouseover event triggers if a mouse pointer enters any child elements as well as the selected element.
The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element. The onmousemove event triggers every time the mouse pointer is moved over the div element.
Events mouseover/mouseout, relatedTarget The mouseover event occurs when a mouse pointer comes over an element, and mouseout – when it leaves.
With .one
:
$('element').one('mouseover', function() { /* ajax */ });
.one
will detach the handler as soon as it is executed. As a result, it won't execute any more times.
You may want to hook your function to the onMouseEnter
event instead of the onMouseOver
event, along with a function hooked to the onMouseLeave
event that hides the tooltip:
$('element').mouseenter(function() {
/* Make request, show tooltip */
});
$('element').mouseleave(function() {
/* Hide tooltip */
});
Note that the pure JS versions of these events are IE only, jQuery simulates the behaviour for other browsers
Use modern JS!
node.addEventListener("mouseover", function() {
// Load data here
}, {once : true});
Documentation, CanIUse
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With