File tree 2 files changed +21
-0
lines changed 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -226,6 +226,16 @@ grid.cell_height(grid.cell_width() * 1.2);
226
226
227
227
Gets current cell width.
228
228
229
+ ### get_cell_from_pixel(position)
230
+
231
+ Get the position of the cell under a pixel on screen.
232
+
233
+ Parameters :
234
+
235
+ - ` position ` - the position of the pixel to resolve in absolute coordinates, as an object with ` top ` and ` left ` properties
236
+
237
+ Returns an object with properties ` x ` and ` y ` i.e. the column and row in the grid.
238
+
229
239
### locked(el, val)
230
240
231
241
Locks/unlocks widget.
Original file line number Diff line number Diff line change 714
714
return Math . ceil ( o . outerWidth ( ) / o . attr ( 'data-gs-width' ) ) ;
715
715
} ;
716
716
717
+ GridStack . prototype . get_cell_from_pixel = function ( position ) {
718
+ var containerPos = this . container . position ( ) ;
719
+ var relativeLeft = position . left - containerPos . left ;
720
+ var relativeTop = position . top - containerPos . top ;
721
+
722
+ var column_width = Math . floor ( this . container . width ( ) / this . opts . width ) ;
723
+ var row_height = this . opts . cell_height + this . opts . vertical_margin ;
724
+
725
+ return { x : Math . floor ( relativeLeft / column_width ) , y : Math . floor ( relativeTop / row_height ) } ;
726
+ } ;
727
+
717
728
scope . GridStackUI = GridStack ;
718
729
719
730
scope . GridStackUI . Utils = Utils ;
You can’t perform that action at this time.
0 commit comments