Skip to content

Instantly share code, notes, and snippets.

@BlackSkorpio
BlackSkorpio / isElementInViewport.js
Created December 5, 2018 20:32 — forked from davidtheclark/isElementInViewport.js
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
@BlackSkorpio
BlackSkorpio / jquery.add-body-class.js
Created December 11, 2018 22:23 — forked from mware/jquery.add-body-class.js
add body class based on the url using RegEx
/* add body class */
var loc = window.location.pathname.match(/^\/?(\w+)\b/);
if(loc) $(document.body).addClass(loc[1].toLowerCase());