admin管理员组文章数量:1391987
I wrote a js code to trigger mouseenter and mouseleave on map areas. It works fine in Chrome and Firefox, but not in Safari, Edge, nor IE.
I really can't understand why.
Here is my javascript :
var areas = document.getElementsByTagName('area');
// set event listener for all objects
for (var i = 0; i < areas.length; i++) {
areas[i].addEventListener('mouseenter', inArea);
areas[i].addEventListener('mouseleave', outArea);
}
// On mouse enter
function inArea() {
console.log('mouseenter');
}
// On mouse leave
function outArea() {
console.log('mouseleave');
}
You can play with it here :
What is wrong with this code ? Or maybe you know an other way to do it ?
Thank you.
I wrote a js code to trigger mouseenter and mouseleave on map areas. It works fine in Chrome and Firefox, but not in Safari, Edge, nor IE.
I really can't understand why.
Here is my javascript :
var areas = document.getElementsByTagName('area');
// set event listener for all objects
for (var i = 0; i < areas.length; i++) {
areas[i].addEventListener('mouseenter', inArea);
areas[i].addEventListener('mouseleave', outArea);
}
// On mouse enter
function inArea() {
console.log('mouseenter');
}
// On mouse leave
function outArea() {
console.log('mouseleave');
}
You can play with it here : https://codepen.io/fantomette/pen/pVdLwM
What is wrong with this code ? Or maybe you know an other way to do it ?
Thank you.
Share Improve this question asked May 7, 2018 at 16:06 JulieJulie 1011 silver badge5 bronze badges 2-
Doesn't work in what way? It produces errors in the developer console? No functionality and no errors? Does it only fail on that
codepen
site, or have you tried it in an actual application where it fails as well? – user2437417 Commented May 7, 2018 at 16:12 - Thank you for your answer. I don't see the console.log in the console on Safari, Edge and IE. There is no error in console. It fails on codepen and on my website. – Julie Commented May 8, 2018 at 7:28
1 Answer
Reset to default 7I replaced "mouseenter" and "mouseleave" by "mouseover" and "mouseout" and it works fine in every browsers.
本文标签: javascriptmouseenter and mouseleave on safariedge and IEStack Overflow
版权声明:本文标题:javascript - mouseenter and mouseleave on safari, edge and IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744685010a2619643.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论