【发布时间】:2015-06-02 06:53:23
【问题描述】:
我正在使用 Tristen Brown 的 hoverintent library,它是 jQuery hoverIntent 库的纯 Javascript 版本。
我有两个元素 first 和 second。
second 元素具有 hoverintent 处理程序,这会导致工具提示出现在该元素上方。当我手动将鼠标悬停在second 上时,工具提示会按预期显示。
我想以编程方式触发second 的工具提示。例如,与first 元素进行交互会导致出现second 元素的工具提示。我曾尝试使用 jQuery trigger 来做到这一点。我可以trigger mouseover 处理程序,但不能使用任何 hoverIntent。
有什么建议吗?
这是我的 Javascript:
$( document ).ready(function() {
var first = document.getElementById('first');
var second = document.getElementById('second');
$(first).mouseover(function(){
$(second).trigger({ type:"mouseover", clientX:"350", clientY:"105" });
$(second).trigger({ type:"mousemove", clientX:"350", clientY:"105" });
});
hoverintent(second, function(e) {
this.className = 'on';
}, function(e) {
this.className = 'off';
});
$(second).mouseover(function(){
console.log("mouseover");
});
});
这是我的 HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src='http://tristen.ca/hoverintent/dist/hoverintent.min.js'></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div style="padding:100px;">
<ul class='examples'>
<li id='first'>
Trigger
</li>
<li id='second'>
hoverintent
<span class='popup'>Hi there</span>
</li>
</ul>
</div>
</body>
</html>
完整的 JS bin 在这里:
【问题讨论】:
标签: javascript jquery hoverintent