vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
31 lines (30 loc) • 931 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const getCurrentDocument_1 = __importDefault(require("./getCurrentDocument"));
/**
* Get the current viewport element (scrolling element) of the current document, from a given element
*
* @param doc - Element to find the viewport element from
* @return The viewport element
*
* @example
*
* ```ts
* // Get the viewport of the current document
* viewport();
*
* // Get the viewport of the current window
* viewport(window);
*
* // Get the viewport of a given element
* viewport(someElementInSomeDocument);
* ```
*/
function viewport(elm) {
const doc = getCurrentDocument_1.default(elm || document);
return doc && (doc.scrollingElement || doc.documentElement);
}
exports.default = viewport;