用油猴划词搜索脚本,划词会弹出图标栏,试了下使用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);
更新:
不挪鼠标可以自动关闭、鼠标放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);
```