Browse Source

Add option for custom autoscrolling function

pull/832/head
Boris Sergeev 9 years ago
parent
commit
f11bf04aaa
  1. 20
      Sortable.js

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