
用油猴划词搜索脚本,划词会弹出图标栏,试了下使用 mouseIn 、mouseOver 函数,把鼠标移到图标栏的时候,都不能不自动消失,一定是哪里弄错了,感谢大佬指导
完整代码
浏览器搜索扩展工具
原先是使用的 mouseIn,添加代码最前面,请问这一块要如何写呢
mouseIn: 0; var TimeOutHide = function () { if (mouseIn === 0) { return fadeOut(icon); } }; var icOnArray= [ { name: '打开', image: 'https://i.ibb.co/PQ5xM2R/2-1.png', host: [''], popup: function (text) { if(text.indexOf("http://")==0||text.indexOf("https://")==0) window.open(text, "_blank"); else window.open("http://"+text, "_blank"); } }, timer = window.setTimeout(TimeOutHide, 6000); 改用原生的js实现mouseenter,提示Cannot read property 'relatedTarget' of undefined
var hide_cOntrols=function(e){ // console.log(this); if(e.relatedTarget!==e.currentTarget&&e.currentTarget.getElementsByClassName(e.relatedTarget.className).length===0){ icon.style.display = 'none'; } } timer = window.setTimeout(hide_controls, 6000); 不挪鼠标可以自动关闭、鼠标放icon上不关闭、快速移开鼠标可以自动关闭
鼠标长时间放icon上,再移开又不自动关闭了,怎么解决呀
var TimeOutHide; var ismouseenter = false; icon.Onmouseenter= function(){ console.log("ismouseenter"); if(ismouseenter == true){ //已经移入直接返回 return; } else { ismouseenter = true; // 状态设为移入 } }; icon.Onmouseleave= function(){ console.log("ismouseleave"); if(ismouseenter == false){ return; } else { ismouseenter = false; } }; TimeOutHide = function () { if (ismouseenter == false) { return fadeOut(icon); console.log("doSomethingOk"); } }; fadeIn(icon); clearTimeout(timer); timer = window.setTimeout(TimeOutHide, 6000); 1 soooulp OP 解决啦,在 icon.onmouseenter 、icon.onmouseleave 中分部加入 clearTimeout(timer);,清除定时就好了 |