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.
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.

20
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);
}

Loading…
Cancel
Save