You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/public/src/modules/scrollStop.js

32 lines
825 B
JavaScript

9 years ago
'use strict';
9 years ago
/*
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 () {
const Module = {};
9 years ago
Module.apply = function (element) {
$(element).on('mousewheel', function (e) {
const scrollTop = this.scrollTop;
const scrollHeight = this.scrollHeight;
const elementHeight = Math.round(this.getBoundingClientRect().height);
9 years ago
if (
(e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up
(e.originalEvent.deltaY > 0 && (elementHeight + scrollTop) >= scrollHeight) // scroll down
9 years ago
) {
return false;
}
});
};
return Module;
8 years ago
});