I'm trying to scroll by highlighting text and dragging it down. Now, as you probably know, this is the default default behavior for a standard item overflow: auto, however I am trying to do this with some fancy scrollbars kindly provided by jQuery jScrollPane from Kelvin Luck.
I created a fiddle here: DEMO
Basically, as you can see, highlighting and scrolling work at the top of the window (by default overflow: auto), but not in the second, and to make matters worse, as soon as you reach the bottom, it DOES NOT WRONG your choice!
So my question is (is) this (these): is there a way to fix this? If so, how?
UPDATE
I worked on this quite a bit and found a small solution using setTimeout()
however, it does not work as intended, and if someone wants to help, I will split it into a new fiddle here: jsFiddle
code itself:
pane = $('#scrolldiv2');
pane.jScrollPane({animateEase: 'linear'});
api = pane.data('jsp');
$('#scrolldiv2').on('mousedown', function() {
$(this).off().on('mousemove', function(e) {
rel = $(this).relativePosition();
py = e.pageY - rel.y;
$t = $(this);
if (py >= $(this).height() - 20) {
scroll = setTimeout(scrollBy, 400, 20);
}
else if (py < 20) {
scroll = setTimeout(scrollBy, 400, -20);
}
else {
clearTimeout(scroll);
}
})
}).on('mouseup', function() {
$(this).off('mousemove');
clearTimeout(scroll);
})
var scrollBy = function(v) {
if (api.getContentPositionY < 20 & v == -20) {
api.scrollByY(v + api.getContentPositionY);
clearTimeout(scroll);
} else if (((api.getContentHeight - $t.height()) - api.getContentPositionY) < 20 & v == 20) {
api.scrollByY((api.getContentHeight - $t.height()) - api.getContentPositionY);
clearTimeout(scroll);
} else {
api.scrollByY(v, true)
scroll = setTimeout(scrollBy, 400, v)
}
}
$.fn.extend({
relativePosition: function() {
var t = this.get(0),
x, y;
if (t.offsetParent) {
x = t.offsetLeft;
y = t.offsetTop;
while ((t = t.offsetParent)) {
x += t.offsetLeft;
y += t.offsetTop;
}
}
return {
x: x,
y: y
}
},
})