Skip to content

Instantly share code, notes, and snippets.

View analytics-scripts's full-sized avatar

analytics-scripts

View GitHub Profile
(function() {
var observer = new IntersectionObserver(function(entries) {
if(entries[0].isIntersecting === true) {
// your work here...
}
//... same for all elemensts if there are more than one. or just check with cycle
//threshold from 0 - just became visible to 1 - fully visible
}, { threshold: [0.5] });
observer.observe(/*elements to observe*/);
const getHashVar = hash_var =>
location.hash.includes(hash_var + '=') ? location.hash.split(hash_var + '=')[1].replace(/&.*/g, "") : "";
@analytics-scripts
analytics-scripts / mapDOM.js
Created December 26, 2019 13:11
convert any dom object to json
function mapDOM(element, json) {
var treeObject = {};
// If string convert to document Node
if (typeof element === "string") {
if (window.DOMParser) {
parser = new DOMParser();
docNode = parser.parseFromString(element,"text/xml");
} else { // Microsoft strikes again
docNode = new ActiveXObject("Microsoft.XMLDOM");
@analytics-scripts
analytics-scripts / parseCookie.js
Created December 12, 2019 09:15
parse cookie
const parseCookie = str =>
str ? str
.split(';')
.map(v => v.split('='))
.reduce((acc, v) => {
acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
return acc;
}, {}) : "";