From f11bf04aaa4bb3d358f9662a44ad43c6638c97a3 Mon Sep 17 00:00:00 2001 From: Boris Sergeev Date: Thu, 21 Apr 2016 19:38:00 +0300 Subject: [PATCH 1/2] Add option for custom autoscrolling function --- Sortable.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index 24664b7..d8445c5 100644 --- a/Sortable.js +++ b/Sortable.js @@ -39,6 +39,7 @@ scrollEl, scrollParentEl, + scrollCustomFn, lastEl, lastCSS, @@ -99,13 +100,17 @@ winHeight = window.innerHeight, vx, - vy + vy, + + scrollOffsetX, + scrollOffsetY ; // Delect scrollEl if (scrollParentEl !== rootEl) { scrollEl = options.scroll; scrollParentEl = rootEl; + scrollCustomFn = options.scrollFn; if (scrollEl === true) { scrollEl = rootEl; @@ -147,11 +152,18 @@ if (el) { autoScroll.pid = setInterval(function () { + scrollOffsetY = vy ? vy * speed : 0; + scrollOffsetX = vx ? vx * speed : 0; + + if ('function' === typeof(scrollCustomFn)) { + return scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt); + } + if (el === win) { - win.scrollTo(win.pageXOffset + vx * speed, win.pageYOffset + vy * speed); + win.scrollTo(win.pageXOffset + scrollOffsetX, win.pageYOffset + scrollOffsetY); } else { - vy && (el.scrollTop += vy * speed); - vx && (el.scrollLeft += vx * speed); + el.scrollTop += scrollOffsetY; + el.scrollLeft += scrollOffsetX; } }, 24); } From b11772918e624c5b70b56fa29d5a7f96b74fff9d Mon Sep 17 00:00:00 2001 From: Boris Sergeev Date: Thu, 21 Apr 2016 19:39:34 +0300 Subject: [PATCH 2/2] Update README.md: info about custom autoscrolling function --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 02faa6e..d038483 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ var sortable = new Sortable(el, { fallbackTolerance: 0 // Specify in pixels how far the mouse should move before it's considered as a drag. scroll: true, // or HTMLElement + scrollFn: function(offsetX, offsetY, originalEvent) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px @@ -336,6 +337,14 @@ Demo: --- +#### `scrollFn` option +Defines function that will be used for autoscrolling. el.scrollTop/el.scrollLeft is used by default. +Useful when you have custom scrollbar with dedicated scroll function. + + +--- + + #### `scrollSensitivity` option Defines how near the mouse must be to an edge to start scrolling.