Files
NodeBB/public/src/modules/scrollStop.js

32 lines
817 B
JavaScript
Raw Normal View History

2016-10-24 11:12:39 -04:00
'use strict';
2016-10-24 11:12:39 -04:00
/*
The point of this library is to enhance(tm) a textarea so that if scrolled,
you can only scroll to the top of it and the event doesn't bubble up to
the document... because it does... and it's annoying at times.
While I'm here, might I say this is a solved issue on Linux?
*/
define('scrollStop', function () {
var Module = {};
Module.apply = function (element) {
$(element).on('mousewheel', function (e) {
var scrollTop = this.scrollTop;
var scrollHeight = this.scrollHeight;
2017-06-30 23:38:52 -06:00
var elementHeight = Math.round(this.getBoundingClientRect().height);
2017-02-18 01:27:46 -07:00
2016-10-24 11:12:39 -04:00
if (
(e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up
(e.originalEvent.deltaY > 0 && (elementHeight + scrollTop) >= scrollHeight) // scroll down
2016-10-24 11:12:39 -04:00
) {
return false;
}
});
};
return Module;
2017-02-18 02:30:48 -07:00
});