Created
July 17, 2014 11:37
-
-
Save rodleviton/6689ebdbec1209353a1a to your computer and use it in GitHub Desktop.
Random element generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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