"css grid layout" = https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
Does anyone know of a javascript way to work out what column / row the mouse is currently in?
I'm guessing something like this is a start for getting the what cell the mouse is in however this would only be useful for grids of equal sizes.
MouseGridColumn = round(mouseX / ( gridContainerWidth / gridTotalColumnsNumber ) )
MouseGridRow = round(mouseY / ( gridContainerHeight / gridTotalRowsNumber ) )
Is there a way to do this with cells that aren't equal?
Here is a codepen which shows 3 various percentage column widths (grid-template-columns: 25% 50% 25%;
), 2 rows, a grid cell with no element with in it and an element that spans more than one row: http://codepen.io/anon/pen/NbeOXp
Here I have added hidden elements to each cell in the grid to detect which cell the mouse is in. However it only returns "auto" for the current element it is in. It's also pretty clunky having to add extra hidden elements to the grid IMO.
http://codepen.io/anon/pen/gLZBZw Hint: use the mouse to hover over the grid.
We can name grid areas. A grid area is a rectangular area consisting of one or more grid cells. The area is defined by four grid lines marking out the start and end lines for columns and rows. We name areas of the grid using the grid-template-areas property.
JavaScript Grid, also known as the JavaScript DataGrid, is a feature-rich control for displaying data in a tabular format. Its wide range of functionalities includes data binding, editing, Excel-like filtering, custom sorting, aggregating rows, selection, and support for Excel, CSV, and PDF formats.
It is definitely safe to use.
Add event listener to the parent of the grid colums. Its called event delegation. You can use event.target
in on hover event and inside for loop compare the ev.target.parent element==document.querySelect("#parentElement")[index]
Post all ur code html code to write it exactly if you want.
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