Skip to content

Instantly share code, notes, and snippets.

@rodleviton
Created July 17, 2014 11:37
Show Gist options
  • Save rodleviton/6689ebdbec1209353a1a to your computer and use it in GitHub Desktop.
Save rodleviton/6689ebdbec1209353a1a to your computer and use it in GitHub Desktop.
Random element generator
var Generator = window.Generator || {};
Generator = (function() {
'use strict';
var container; // Container to append items to and get size constraints
function init(id, total, className) {
container = document.getElementById(id);
// Generate some random divs
for (var i = 0; i <= total; i++) {
var el = document.createElement('div');
el.className = className + ' item item-' + (i + 1);
el.style.position = 'absolute';
updatePosition(el);
container.appendChild(el);
}
}
function updatePosition(el) {
var top = Math.round(Math.random() * container.offsetWidth),
left = Math.round(Math.random() * container.offsetHeight);
el.style.top = top + 'px';
el.style.left = left + 'px';
}
return {
init: init
};
})();
$(function() {
'use strict';
Generator.init('scene', 10, 'bubble');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment