Browse Source

Merge pull request #884 from vasiakorobkin/custom_autoscrolling_function

Custom autoscrolling function
pull/754/merge
Lebedev Konstantin 9 years ago committed by GitHub
parent
commit
d2e3a6fa45
  1. 9
      README.md
  2. 20
      Sortable.js

9
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. fallbackTolerance: 0 // Specify in pixels how far the mouse should move before it's considered as a drag.
scroll: true, // or HTMLElement 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. scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling.
scrollSpeed: 10, // px 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 #### `scrollSensitivity` option
Defines how near the mouse must be to an edge to start scrolling. Defines how near the mouse must be to an edge to start scrolling.

20
Sortable.js

@ -39,6 +39,7 @@
scrollEl, scrollEl,
scrollParentEl, scrollParentEl,
scrollCustomFn,
lastEl, lastEl,
lastCSS, lastCSS,
@ -99,13 +100,17 @@
winHeight = window.innerHeight, winHeight = window.innerHeight,
vx, vx,
vy vy,
scrollOffsetX,
scrollOffsetY
; ;
// Delect scrollEl // Delect scrollEl
if (scrollParentEl !== rootEl) { if (scrollParentEl !== rootEl) {
scrollEl = options.scroll; scrollEl = options.scroll;
scrollParentEl = rootEl; scrollParentEl = rootEl;
scrollCustomFn = options.scrollFn;
if (scrollEl === true) { if (scrollEl === true) {
scrollEl = rootEl; scrollEl = rootEl;
@ -147,11 +152,18 @@
if (el) { if (el) {
autoScroll.pid = setInterval(function () { 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) { if (el === win) {
win.scrollTo(win.pageXOffset + vx * speed, win.pageYOffset + vy * speed); win.scrollTo(win.pageXOffset + scrollOffsetX, win.pageYOffset + scrollOffsetY);
} else { } else {
vy && (el.scrollTop += vy * speed); el.scrollTop += scrollOffsetY;
vx && (el.scrollLeft += vx * speed); el.scrollLeft += scrollOffsetX;
} }
}, 24); }, 24);
} }

Loading…
Cancel
Save