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.
Any help is appreciated.
Use document. elementFromPoint(x, y) method to get the element content on that position when mouse pointer moves over.
jQuery mouseover() Method The mouseover() method triggers the mouseover event, or attaches a function to run when a mouseover event occurs. Note: Unlike the mouseenter event, the mouseover event triggers if a mouse pointer enters any child elements as well as the selected element.
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');
}
});
Here's a jsFiddle
May be you can do like as follows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With