鼠标悬停在链接上后进入失败
Mouseenter failing after hovering over a link
我有一个函数,添加一个信息div当我悬停在一个文本段落,但当我从正常文本在段落到一个超链接鼠标悬停事件停止,不会重新启动,直到我的鼠标离开段落,并重新悬停在它。如果我从链接开始,它会显示,但如果我从链接跳转到文本或从文本跳转到链接,它总是会停止。
段落例子:
<div id="NoteHolder">
<div class="wrap">
<p class="NoteOp inline date1471280868332">Example sentence <a target="_blank" class="a" href="https://www.example.com">https://www.example.com</a></p>
</div>
</div>
当我将鼠标悬停在段落上时,它会将日期数字类转换为人类可读的日期,并显示在div中。
Mouseover事件:
$('#NoteHolder').on( "mouseenter", ".NoteOp", function() {
var Info = document.createElement('div');
Info.className = 'EditInfo'
var DateP = document.createElement('p');
DateP.className = 'DivP';
var DatePT = document.createTextNode(PT)
DateP.appendChild(DatePT);
Info.appendChild(DateP);
var position = $(this).position();
var thisX = position.left;
var thisY = position.top;
var thisWidth = $(this).width();
var thisHeight = $(this).height();
var PageW = $('html').width();
if(thisX + thisWidth + 50 > PageW) {
$(Info).css({
"left": thisX + thisWidth + 20,
"top": thisY - 10
});
}
document.getElementById("NoteHolder").appendChild(Info);
});
$('#NoteHolder').on( "mouseout", ".NoteOp", function() {
$(".EditInfo").remove();
});
是否有办法从删除这个div当我悬停在链接?
你的代码中有一个打字错误,额外的右括号导致了这个问题,下面是更正后的代码
$(function() {
$('#NoteHolder').on( "mouseover", ".NoteOp", function() {
alert("Enter");
var Info = document.createElement('div');
Info.className = 'EditInfo'
var DateP = document.createElement('p');
DateP.className = 'DivP';
var DatePT = document.createTextNode(PT)
DateP.appendChild(DatePT);
Info.appendChild(DateP);
var position = $(this).position();
var thisX = position.left;
var thisY = position.top;
var thisWidth = $(this).width();
var thisHeight = $(this).height();
var PageW = $('html').width();
if(thisX + thisWidth + 50 > PageW) {
$(Info).css({
"left": thisX + thisWidth + 20,
"top": thisY - 10
});
}
document.getElementById("NoteHolder").appendChild(Info);
});
$('#NoteHolder').on( "mouseout", ".NoteOp", function() {
alert("Exit");
$(".EditInfo").remove();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="NoteHolder">
<div class="wrap">
<p class="NoteOp inline date1471280868332">Example sentence <a target="_blank" class="a" href="https://www.example.com">https://www.example.com</a></p>
</div>
</div>
当您使用jQuery时,您可以通过$("<div/>")
而不是document.createElement('div')
创建动态div
相关文章:
- 当鼠标悬停在文本中的单词上时显示警报
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 手风琴可点击并悬停
- 悬停功能触发器
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- css(或jQuery)悬停时淡入淡出
- 当json解析空响应时,Whatwg-Fetch失败,我该如何防止它
- jquery快速悬停问题
- JsFiddle在分叉后描述失败
- 如何在悬停时流畅地更改单词
- jQuery:当屏幕大小改变时,如何更改默认图像和悬停图像
- 悬停下拉菜单即使在鼠标移出后也保持活动状态
- Jquery 悬停函数在将鼠标悬停在选择框上时会失败
- Jquery悬停在子分区输入时失败
- 鼠标悬停在链接上后进入失败
- 鼠标悬停/移出时更改图标失败
- 当鼠标悬停在图像上时鼠标悬停失败
- 使用jquery / js检查项目悬停失败