Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
developering...

Jamie Murphy jjmu15

💭
developering...
View GitHub Profile
@jjmu15
jjmu15 / getURLParam.js
Created Apr 7, 2014
js get url paramter
View getURLParam.js
function urlParam(name){
var results = new RegExp("[\\?&]" + name + "=([^&#]*)").exec(window.location.href);
if(results) {
return results[1];
}
return false;
}
@jjmu15
jjmu15 / off_event.js
Created Jan 31, 2014
off event trigger - vanilla js
View off_event.js
function removeEventListener(el, eventName, handler) {
if (el.removeEventListener)
el.removeEventListener(eventName, handler)
else
el.detachEvent('on' + eventName, handler)
}
removeEventListener(el, eventName, handler)
@jjmu15
jjmu15 / on_event.js
Created Jan 31, 2014
on event trigger - vanilla js
View on_event.js
function addEventListener(el, eventName, handler) {
if (el.addEventListener)
el.addEventListener(eventName, handler)
else
el.attachEvent('on' + eventName, handler)
}
addEventListener(el, eventName, handler)
@jjmu15
jjmu15 / remove_class.js
Created Jan 31, 2014
remove class - vanilla js
View remove_class.js
if (el.classList)
el.classList.remove(className)
else
el.className = el.className.replace(new RegExp('(^| )' + className.split(' ').join('|') + '( |$)', 'gi'), ' ')
@jjmu15
jjmu15 / remove_element.js
Created Jan 31, 2014
remove element - vanilla js
View remove_element.js
el.parentNode.removeChild(el)
@jjmu15
jjmu15 / find_children.js
Created Jan 31, 2014
find children - vanilla js
View find_children.js
el.querySelectorAll(selector)
@jjmu15
jjmu15 / filter.js
Created Jan 31, 2014
filter - vanilla js
View filter.js
function filter(selector, filterFn) {
var elements = document.querySelectorAll(selector)
var out = []
for (var i = elements.length; i--;) {
if (filterFn(elements[i]))
out.unshift(elements[i])
}
return out
}
@jjmu15
jjmu15 / foreach.js
Created Jan 31, 2014
foreach element - vanilla js
View foreach.js
function forEachElement(selector, fn) {
var elements = document.querySelectorAll(selector)
for (var i = 0; i < elements.length; i++)
fn(elements[i], i)
}
forEachElement(selector, function(el, i){
})
@jjmu15
jjmu15 / add_class
Created Jan 31, 2014
add class - vanilla js
View add_class
if (el.classList)
el.classList.add(className)
else
el.className += ' ' + className
@jjmu15
jjmu15 / fade_in.js
Created Jan 31, 2014
fadeIn vanilla JS
View fade_in.js
function fadeIn(el) {
var opacity = 0
el.style.opacity = 0
el.style.filter = ''
var last = +new Date
var tick = function() {
opacity += (new Date - last) / 400
el.style.opacity = opacity