Returns the scroll position of the current page.
Window.pageXOffset
and Window.pageYOffset
if they are defined, otherwise Element.scrollLeft
and Element.scrollTop
.el
, to use the global Window
object.const getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
});
getScrollPosition(); // {x: 0, y: 200}
JavaScript, Browser
Redirects the page to HTTPS if it's currently in HTTP.
JavaScript, Browser
Smooth-scrolls to the top of the page.
JavaScript, Browser
Gets the protocol being used on the current page.