Skip to content

Instantly share code, notes, and snippets.

View fiveminuteargument's full-sized avatar

Bobby Jack fiveminuteargument

View GitHub Profile
document.getElementById('c1').classList.toggle('blinkon');
getLayout: function(el) {
var props = { width: 'Width', height: 'Height', left: 'Left', top: 'Top' };
for (var p in props)
props[p] = el['offset' + props[p]];
while (el = el.offsetParent) {
props.left += el.offsetLeft;
props.top += el.offsetTop;
}
@fiveminuteargument
fiveminuteargument / removeChildren.js
Created March 26, 2013 00:43
Remove all children of a DOM Node
while (el.firstChild)
el.removeChild(el.firstChild);
@fiveminuteargument
fiveminuteargument / visit-nodes-iterative.js
Last active February 24, 2016 08:27
Iterative approach to walking a DOM tree in javascript
function visit_nodes_iterative(node) {
node = node || document;
do
{
/* Do something with node here */
node = node.firstChild || node.nextSibling || function() {
while ((node = node.parentNode) && !node.nextSibling);
return node ? node.nextSibling : null;
@fiveminuteargument
fiveminuteargument / closure_inheritance.js
Created April 12, 2012 13:33 — forked from creationix/closure_inheritance.js
A simple 'OO' closure example
// Requires node v0.1.100 or a browser with console
function newShape(x, y) {
return {
toString: function () {
return 'Shape at ' + x + ', ' + y;
}
};
}
@fiveminuteargument
fiveminuteargument / sitemap.css
Created January 3, 2012 19:00
Supporting files for kirbycms sitemap snippet
.sitemap ul { margin: 0.5em 0 0.5em 2em; }
.sitemap li { margin-bottom: 0.5em; }
@fiveminuteargument
fiveminuteargument / jquery.zap.js
Created March 17, 2010 11:04
Jquery function to remove an element but not its children
$.fn.zap = function () { return this.each(function(){ $(this.childNodes).insertBefore(this); }).remove(); };
@fiveminuteargument
fiveminuteargument / array-shuffle.js
Created March 17, 2010 11:00 — forked from remy/gist:333954
Pure JS fork enabling script embedding (if you're crazy!)
function shuffle(array) { return array.sort(function(){ return .5 - Math.random(); }); }