admin管理员组文章数量:1391960
I have an image in a page and in the onmouseover
event of that image I will call a JavaScript function to show a tooltip and in the onmouseout
of the image, I will call a method to hide the tooltip. Now I found that when I place the cursor on the image, it's calling the method to show the tooltip div.
And if I move the mouse within the image, it's calling the onmouseout
event (even if I am not out of the image). How can I stop this? I want onmouseout
to be called when the cursor is out of the image. Any thoughts?
Here is how I call it:
<img src="images/customer.png" onmouseout="HideCustomerInfo()" onmouseover="ShowCustomerInfo(485)" />
And in my JavaScript:
function ShowCustomerInfo(id) {
var currentCustomer = $("#hdnCustomerId").val();
if (currentCustomer != id) { // to stop making an ajax call everytime when the mouse move on the same image
$.get('../Lib/handlers/userhandler.aspx?mode=custinfo&cid=' + id, function (data) {
strHtml = data;
});
tooltip.show(strHtml); // method in another jquery pluggin
$("#hdnCustomerId").val(id);
}
}
function HideCustomerInfo() {
tooltip.hide(); // method in another jquery pluggin
$("#hdnCustomerId").val(0); //setting in a hidden variable in the page
}
I have an image in a page and in the onmouseover
event of that image I will call a JavaScript function to show a tooltip and in the onmouseout
of the image, I will call a method to hide the tooltip. Now I found that when I place the cursor on the image, it's calling the method to show the tooltip div.
And if I move the mouse within the image, it's calling the onmouseout
event (even if I am not out of the image). How can I stop this? I want onmouseout
to be called when the cursor is out of the image. Any thoughts?
Here is how I call it:
<img src="images/customer.png" onmouseout="HideCustomerInfo()" onmouseover="ShowCustomerInfo(485)" />
And in my JavaScript:
function ShowCustomerInfo(id) {
var currentCustomer = $("#hdnCustomerId").val();
if (currentCustomer != id) { // to stop making an ajax call everytime when the mouse move on the same image
$.get('../Lib/handlers/userhandler.aspx?mode=custinfo&cid=' + id, function (data) {
strHtml = data;
});
tooltip.show(strHtml); // method in another jquery pluggin
$("#hdnCustomerId").val(id);
}
}
function HideCustomerInfo() {
tooltip.hide(); // method in another jquery pluggin
$("#hdnCustomerId").val(0); //setting in a hidden variable in the page
}
Share
Improve this question
edited Sep 30, 2020 at 7:18
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Sep 27, 2010 at 16:17
ShyjuShyju
219k106 gold badges420 silver badges498 bronze badges
4 Answers
Reset to default 2I am assuming you are mousing over your tooltip? and the tooltip has its markup outside the realm of the image?
So by mousing over the tooltip you are technically leaving the image. I have had similar things happen to me.
To get around this, try sticking a div
around the image, and putting the mouse event on the div
, then as a child element to the div
have your tooltip, so even when you are then mousing over the tooltip, you are still inside the div
.
That might work.
Another easy way to get around this is by setting pointer-events: none
on your tooltip
If the image tht you are using to hover over has transparency (it's a png, right), then when you move the mouse over a transparent portion of the image you'll get an onmouseout event. yeah, it sucks. I have the same problem and no elegant solution for it yet.
Are you sure HideCustomerInfo()
is called by the onmouseout
event handler of the image? Also, what browsers do you get that in? Do you get this behavior in one particular browser?
本文标签:
版权声明:本文标题:onmouseout JavaScript event being called when I move the cursor over an element without going out of the element - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744716072a2621410.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论