I assume that it is defined as an algorithm, we want the dragged object, when we scroll, to stay where the mouse is. So we need the onScroll event somewhere.
Usually we just update the position of the object with the mouse, but onScroll does not seem to be attached to it. To paraphrase it, we can say that we want the object to move / shift by n the amount equal to the amount that we scroll. It might work.
Of course, in order to compensate for the object, you need to play a trick on the grid. But I think something like this might work:
var gridster = $(".gridster ul").gridster({ widget_base_dimensions: [100, 55], widget_margins: [5, 5], draggable: { start: function (e, ui, $widget) { var that = this , //to access gridster from inside onscroll oldScroll = $(document).scrollTop() //to calculate scroll change obj = $(this.helper ? this.$helper : this.$player) //draggable/helper $(document).on("scroll", function () { //calculate scroll change var curr = $(document).scrollTop() var diff = curr-oldScroll oldScroll = curr //add change to stored offset for gridster that.drag_api.el_init_offset.top += diff //show change temporarily because gridster doesn't update obj.css({ 'top': parseFloat(obj.css("top")) + diff }); }) }, stop: function (e, ui, $widget) { $(document).off("scroll") } } }).data('gridster');
Example
I think this will be a good starting point. Current reservations, the grid itself is not updated to another mousemove. You may need to poke more.
Update
The above code breaks down into drag-and-drop scrolls, since the grid has its own scroll implementation. Looking at the problem, I could not find a way to distinguish between scrolling and normal scrolling (looked at onMouseWheel and DOMMouseScroll , but did not look like it was well supported. Therefore, I believe that a quick fix will disable the scroll offset if it is close to the edge, so add the following values:
//change stored offset for gridster if not on edge if(!that.edge) that.drag_api.el_init_offset.top += diff
And we need to check the drag and drop. Therefore, we add a drag and drop handler to the gridster. Sort of:
drag:function(e,ui,$widget){ //check if edge var pixelFromEdge=100 this.edge= e.clientY< pixelFromEdge || $("html")[0].clientHeight-e.clientY < pixelFromEdge },
Demo
Honestly, he feels that this is probably a better and more elegant solution (not completely modifying the plugin, which is likely to be much simpler)