Skip to content

Instantly share code, notes, and snippets.

@luis-fss
Last active March 16, 2016 03:00
Show Gist options
  • Save luis-fss/4b44c7b7a8ea0561a23d to your computer and use it in GitHub Desktop.
Save luis-fss/4b44c7b7a8ea0561a23d to your computer and use it in GitHub Desktop.
testar cores em javascript
// testar cores em javascript
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var coloursOriginal = ["#16a085", "#c0392b", "#8e44ad", "#bdc3c7", "#e67e22", "#2ecc71", "#7f8c8d", "#95a5a6", "#2980b9", "#1abc9c", "#27ae60", "#3498db", "#9b59b6", "#d35400", "#2c3e50", "#f1c40f", "#e74c3c", "#34495e", "#f39c12"];
var colours = ["#16a085", "#c0392b", "#748bf1", "#bdc3c7", "#e67e22", "#2ecc71", "#7f8c8d", "#da799e", "#2980b9", "#1abc9c", "#27ae60", "#3498db", "#9b59b6", "#d35400", "#998527", "#f1c40f", "#e74c3c", "#11478b", "#ba1d9b"];
//console.log(colours);
//var c = shuffle(colours);
//console.log(c);
$('<div/>').attr('id','ola').appendTo("body");
for (var i = 0; i < colours.length; i++) {
var t = (i + 1).toString();
if(t.length == 1) t = 0+t;
$('<span/>').css('background-color', colours[i])
//.css('position', 'relative')
.attr('id','c'+i)
.css('padding','15px')
//.width(50).height(50)
.text(t)
//.insertAfter('div:last')
.appendTo("#ola")
;
}
$('<br/>').insertAfter('#c9');
$('<br/>').insertAfter('#c9');
$('<br/>').insertAfter('#c9');
@luis-fss
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment