Skip to content

Instantly share code, notes, and snippets.

View dhunmoon's full-sized avatar

Atul Chaudhary dhunmoon

View GitHub Profile
@dhunmoon
dhunmoon / getDocumentPageHeight.js
Created August 16, 2022 09:26
Get document height
/**
* Document sizes are a browser compatibility nightmare because, although all browsers expose clientHeight and s
* crollHeight properties, they don't all agree how the values are calculated.
* @return {float} Height of the page after calulation.
* */
function getDocumentHeight(){
var body = document.body,
html = document.documentElement;
@dhunmoon
dhunmoon / addEventHandler.js
Created July 21, 2023 11:47
Adding event to an element (backward compatable)
/**
* @param {Object} el Element where the event needed to be added
* @param {string} type Type of event which is getting added
* @param {function} handler Event handler which will get called.
*/
function addHandler(el, type, handler) {
//overwrite the existing function
if (el.addEventListener){ //DOM2 Events
addHandler = function(el, type, handler) {
el.addEventListener(type, handler, false)