Skip to content

Instantly share code, notes, and snippets.

@netsi1964
netsi1964 / ipinfo.js
Last active October 30, 2019 08:59
Vanilla javascript XHR request to ipinfo.io
function ipinfo(cb, ip) {
var request;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP');
@eltonmesquita
eltonmesquita / onViewport.js
Last active November 1, 2020 09:32
A simple jQuery function that adds a class when the target(s) is in the viewport
function onViewport(el, elClass, offset, callback) {
/*** Based on http://ejohn.org/blog/learning-from-twitter/ ***/
var didScroll = false;
var this_top;
var height;
var top;
if(!offset) { var offset = 0; }
$(window).scroll(function() {