将hoverIntent 与“mousedown”集成
大家好,我有一个 HTML 表格,我正在尝试创建一些 Excel 样式的功能,例如复制和选择单元格等。我有一些很酷的效果(在表格单元格上使用 jQuery 的 mousedown),但它太跳跃了。我了解了hoverIntent,但我不知道如何实现它。它如何适应这个(简化的复制功能):
$("table#grid td").mousedown(function () {
// this cell has the value to copy; retrieve and store it
mouseDown = true;
}).mouseover(function () {
if(mouseDown) {
// copy value into this cell
}
};
$(document).mouseup(function () {
mouseDown = false;
// reset copy info
}
问题是,当跨越 td 边界时,它会多次(有时)注册鼠标悬停,这使得格式化选定/取消选定的单元格成为一场噩梦。
我希望这是有道理的。我对 jQuery 很陌生,但正在努力。
Hey all, I've got an HTML table, and I'm trying to create some Excel style functions like copying and selecting cells and such. I had some cool effects going (using jQuery's mousedown on table cells), but it was too jumpy. I learned about hoverIntent, but I can't figure out how to implement it. How would it fit in with this (simplified copy function):
$("table#grid td").mousedown(function () {
// this cell has the value to copy; retrieve and store it
mouseDown = true;
}).mouseover(function () {
if(mouseDown) {
// copy value into this cell
}
};
$(document).mouseup(function () {
mouseDown = false;
// reset copy info
}
The problem is that it would register a mouseover more than once (some times) when crossing td borders, which was making formatting selected/deselected cells a nightmare.
I hope this makes sense. I'm quite new to jQuery, but trying hard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这绝对是棘手的。 HoverIntent 将有助于解决草率或意外的鼠标操作,但它可能无法解决您的问题。我在这里写的关于如何使用它的任何内容都只是 hoverIntent 文档。
如果这还不够,我建议您更好地熟悉 jQuery 的事件对象< /a>.完成后,您会发现必须使用
event.target
、event.currentTarget
和/或event 进行大量微观管理。相关目标
。换句话说,将事件目标与单元格格式(可能还有所选单元格的日志)进行比较,以确定给定的鼠标悬停触发器是否“失火”。
This is definitely tricky. HoverIntent will help with sloppy or accidental mousing, but it may not solve your problems. Anything I would write here for how to use it would just be a reproduction of the hoverIntent documentation.
In the event that this is not enough, I suggest you become better acquainted with jQuery's event object. Once you do, you'll see that you have to do a good bit of micromanagement, using
event.target
,event.currentTarget
, and/orevent.relatedTarget
.In other words, compare your event targets with cell formatting – and possibly a log of selected cells – to determine whether a given mouseover trigger is a "misfire" or not.