检测鼠标是否在列边框上 [英] Detect if mouse is over a column border
本文介绍了检测鼠标是否在列边框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何通过jQuery或JavaScript检测鼠标是否在列边框或单元格边框上?
Does anybody know how can I detect if mouse is over a column border or a cell border, either by jQuery or JavaScript?
我想实现
I want to implement a column resizing on a specific table.
任何帮助。
推荐答案
你应该检查offsetX和offsetY是否小于border-width,如果是,你在边框,也检查是否offsetX大于innerWidth或offsetY大于innerHeight
You should check if the offsetX and offsetY are less than the border-width and if so you're in the border, also check if offsetX is greater than innerWidth or offsetY is greater than innerHeight
$('td').hover(function(e){
var border_width = parseInt($(this).css('border-width'));
if(e.offsetX < border_width || e.offsetX > $(this).innerWidth() || e.offsetY < border_width || e.offsetY > $(this).innerHeight()){
console.log('This is the border');
}
});
这篇关于检测鼠标是否在列边框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文