Merge pull request #723 from toptalo/issue-689

Add normalization to mousewheel event to fix scroll speed issue
This commit is contained in:
Valeriy Chupurnov 2020-06-23 12:17:39 +03:00 committed by GitHub
commit 441cb69610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 33 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -795,7 +795,30 @@ var datetimepickerFactory = function ($) {
} }
return out; return out;
}, },
getWheelDelta = function (e) {
var deltaY = 0;
if ('detail' in e) { deltaY = e.detail; }
if ('wheelDelta' in e) { deltaY = -e.wheelDelta / 120; }
if ('wheelDeltaY' in e) { deltaY = -e.wheelDeltaY / 120; }
if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) { deltaY = 0; }
deltaY *= 10;
if ('deltaY' in e) { deltaY = e.deltaY; }
if (deltaY && e.deltaMode) {
if (e.deltaMode === 1) {
deltaY *= 40;
} else {
deltaY *= 800;
}
}
return deltaY;
},
timebox, timebox,
timeboxTop = 0,
parentHeight, parentHeight,
height, height,
scrollbar, scrollbar,
@ -816,6 +839,7 @@ var datetimepickerFactory = function ($) {
if (!$(this).hasClass('xdsoft_scroller_box')) { if (!$(this).hasClass('xdsoft_scroller_box')) {
timebox = timeboxparent.children().eq(0); timebox = timeboxparent.children().eq(0);
timeboxTop = Math.abs(parseInt(timebox.css('marginTop'), 10));
parentHeight = timeboxparent[0].clientHeight; parentHeight = timeboxparent[0].clientHeight;
height = timebox[0].offsetHeight; height = timebox[0].offsetHeight;
scrollbar = $('<div class="xdsoft_scrollbar"></div>'); scrollbar = $('<div class="xdsoft_scrollbar"></div>');
@ -841,7 +865,7 @@ var datetimepickerFactory = function ($) {
} }
startY = pointerEventToXY(event).y; startY = pointerEventToXY(event).y;
startTopScroll = parseInt(scroller.css('margin-top'), 10); startTopScroll = parseInt(scroller.css('marginTop'), 10);
h1 = scrollbar[0].offsetHeight; h1 = scrollbar[0].offsetHeight;
if (event.type === 'mousedown' || event.type === 'touchstart') { if (event.type === 'mousedown' || event.type === 'touchstart') {
@ -877,12 +901,10 @@ var datetimepickerFactory = function ($) {
timeboxparent.trigger('resize_scroll.xdsoft_scroller', [percentage, true]); timeboxparent.trigger('resize_scroll.xdsoft_scroller', [percentage, true]);
} }
percentage = percentage > 1 ? 1 : (percentage < 0 || isNaN(percentage)) ? 0 : percentage; percentage = percentage > 1 ? 1 : (percentage < 0 || isNaN(percentage)) ? 0 : percentage;
timeboxTop = parseFloat(Math.abs((timebox[0].offsetHeight - parentHeight) * percentage).toFixed(4));
scroller.css('margin-top', maximumOffset * percentage); scroller.css('marginTop', maximumOffset * percentage);
timebox.css('marginTop', -timeboxTop);
setTimeout(function () {
timebox.css('marginTop', -parseInt((timebox[0].offsetHeight - parentHeight) * percentage, 10));
}, 10);
}) })
.on('resize_scroll.xdsoft_scroller', function (event, percentage, noTriggerScroll) { .on('resize_scroll.xdsoft_scroller', function (event, percentage, noTriggerScroll) {
var percent, sh; var percent, sh;
@ -897,19 +919,14 @@ var datetimepickerFactory = function ($) {
scroller.css('height', parseInt(sh > 10 ? sh : 10, 10)); scroller.css('height', parseInt(sh > 10 ? sh : 10, 10));
maximumOffset = scrollbar[0].offsetHeight - scroller[0].offsetHeight; maximumOffset = scrollbar[0].offsetHeight - scroller[0].offsetHeight;
if (noTriggerScroll !== true) { if (noTriggerScroll !== true) {
timeboxparent.trigger('scroll_element.xdsoft_scroller', [percentage || Math.abs(parseInt(timebox.css('marginTop'), 10)) / (height - parentHeight)]); timeboxparent.trigger('scroll_element.xdsoft_scroller', [percentage || timeboxTop / (height - parentHeight)]);
} }
} }
}); });
timeboxparent.on('mousewheel', function (event) { timeboxparent.on('mousewheel', function (event) {
var top = Math.abs(parseInt(timebox.css('marginTop'), 10)); var deltaY = getWheelDelta(event.originalEvent);
var top = Math.max(0, timeboxTop - deltaY);
top = top - (event.deltaY * 20);
if (top < 0) {
top = 0;
}
timeboxparent.trigger('scroll_element.xdsoft_scroller', [top / (height - parentHeight)]); timeboxparent.trigger('scroll_element.xdsoft_scroller', [top / (height - parentHeight)]);
event.stopPropagation(); event.stopPropagation();
return false; return false;
@ -917,7 +934,7 @@ var datetimepickerFactory = function ($) {
timeboxparent.on('touchstart', function (event) { timeboxparent.on('touchstart', function (event) {
start = pointerEventToXY(event); start = pointerEventToXY(event);
startTop = Math.abs(parseInt(timebox.css('marginTop'), 10)); startTop = timeboxTop;
}); });
timeboxparent.on('touchmove', function (event) { timeboxparent.on('touchmove', function (event) {