I want a DIV to unhide and appear at the mouse cursor when the user hovers over a SPAN or DIV.
I made this function but it does not work (jquery is loaded).
function ShowHoverDiv(divid){
function(e){
var left = clientX + "px";
var top = clientY + "px";
$("#"+divid).toggle(150).css("top",top).css("left",left).css("position","fixed");
return false;
}
}
<div id="divtoshow" style="display:none">test</div>
<br><br>
<span onmouseover="ShowHoverDIV('divtoshow')">Mouse over this</span>
In computing, a mouseover , mouse hover or hover box is a graphical control element that is activated when the user moves or hovers the pointer over a trigger area, usually with a mouse, but also possible with a digital pen. Mouseover control elements are common in web browsers.
On desktop, it is used in conjunction with a cursor, usually a pointer, whereby the tooltip appears when a user hovers the pointer over an item without clicking it.
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.
You're pretty much there:
function hoverdiv(e,divid){
var left = e.clientX + "px";
var top = e.clientY + "px";
var div = document.getElementById(divid);
div.style.left = left;
div.style.top = top;
$("#"+divid).toggle();
return false;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="divtoshow" style="position: fixed;display:none;">test</div>
<br><br>
<span onmouseover="hoverdiv(event,'divtoshow')" onmouseout="hoverdiv(event,'divtoshow')">Mouse over this</span>
i quickly set up this example, starting with Dušan Radojević code:
$("#spanhovering").hover(function(event) {
$("#divtoshow").css({top: event.clientY, left: event.clientX}).show();
}, function() {
$("#divtoshow").hide();
});
jsfiddle
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