Created
April 26, 2016 14:26
-
-
Save rask/0dbbd301345c07b83d0aa7b6a113d0dc to your computer and use it in GitHub Desktop.
Revisions
-
rask created this gist
Apr 26, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ /** * document-scrolltop-shim.js * * Cross-browser adjustments for getting and setting the current scrollTop -value for * the body/html element. * * @author Otto Rask */ /** * Get the scrollTop from either body or html element. As only one * or the other is used in a browser, it returns zero (correct), * or if either value is set to something else than 0 then the * value. * * @return int */ var getDocumentScrollTop = function () { return document.body.scrollTop || document.documentElement.scrollTop || 0; }; /** * Set the scrollTop value. Setting to both should work as browsers * only use one or the other. * * @param int val */ var setDocumentScrollTop = function (val) { document.body.scrollTop = val; document.documentElement.scrollTop = val; };