Skip to content

Commit

Permalink
嵌套移动滚动条问题的修改
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerkay committed Apr 19, 2016
1 parent bc04347 commit 25c3807
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

tapEvt,
touchEvt,
startEvt,

moved,

Expand Down Expand Up @@ -99,14 +100,20 @@
// Delect scrollEl
if (scrollParentEl !== rootEl) {
scrollEl = options.scroll;
scrollParentEl = rootEl;
//scrollParentEl = rootEl;

if (scrollEl === true) {
scrollEl = rootEl;

var yx = abs(startEvt.clientX - evt.clientX), yy = abs(startEvt.clientY - evt.clientY);

//设置一个10像素的移动误差
if (yx % 10 == 0 || yy % 10 == 0)
startEvt = evt;

do {
if ((scrollEl.offsetWidth < scrollEl.scrollWidth) ||
(scrollEl.offsetHeight < scrollEl.scrollHeight)
if ((yx > yy && scrollEl.offsetWidth < scrollEl.scrollWidth) ||
((yx < yy && scrollEl.offsetHeight < scrollEl.scrollHeight))
) {
break;
}
Expand Down Expand Up @@ -324,6 +331,7 @@

if (target && !dragEl && (target.parentNode === el)) {
tapEvt = evt;
startEvt = evt;

rootEl = el;
dragEl = target;
Expand Down Expand Up @@ -496,42 +504,9 @@
_css(ghostEl, 'msTransform', translate3d);
_css(ghostEl, 'transform', translate3d);

//拖拽时联动滚动条
_aScroll();

evt.preventDefault();
}


//扩展滚动条区域自动滚动
function _aScroll() {
if (!(opts && opts.scrollContainer))
return;
var scrollEL = document.getElementById(opts.scrollContainer),
sl = scrollEL.getBoundingClientRect().left,
sr = scrollEL.getBoundingClientRect().left + scrollEL.offsetWidth,
gl = ghostEl.getBoundingClientRect().left, gr = ghostEl.getBoundingClientRect().right;
if (gr > sr) {
_timeScorll(function () {
scrollEL.scrollLeft = scrollEL.scrollLeft + 1;
});
}
if (gl < sl)
_timeScorll(function () {
scrollEL.scrollLeft = scrollEL.scrollLeft - 1;
});

function _timeScorll(f) {
var i = 0;
var sTimer = setInterval(function () {
i++;
f();
if (i == 20)
clearInterval(sTimer);
}, 30);
};
}

},

_appendGhost: function () {
Expand Down

0 comments on commit 25c3807

Please sign in to comment.