Using this link, I created a loading bars div with HTML and CSS
http://www.paulund.co.uk/css-loading-spinners
However, now I want to use JS to create such a loading bar; I want use a function that defines css's height, width and some other attributes and that defines how many bar divs are used for the loading bar. I understand that there are many libraries out there that do such, but I'd rather not use these for now while I'm still learning JS/jQuery/CSS.
What would need to be appended to the style element would be:
.loading{
width: 100px;
height: 100px;
margin: 30px auto;
position: relative;
}
.loading.bar div{
width: 10px;
height: 30px;
border-radius:5px;
background: black;
position: absolute;
top: 35px;
left: 45px;
opacity: 0.05;
-webkit-animation: fadeit 1.1s linear infinite;
animation: fadeit 1.1s linear infinite;
}
.loading.bar div:nth-child(1){
-webkit-transform: rotate(0deg) translate(0, -30px);
transform: rotate(0deg) translate(0, -30px);
-webkit-animation-delay:0s;
animation-delay:0s;
}
Where I would need to define widths, heights, each nth-child...
So my question is the following even in the right direction at all? Also, does it even make sense to be trying to do this? I mean, I want to learn; however, I don't want to learn something that seems unnecessary.
<script>
function addSpinner(bar_amount, time_incr, height, width, margin){
//
//$('head').removeClass('load');
$('<style>.load{width: ' + width + 'px; height: ' + height + 'px; margin: ' + margin + 'px auto; position: relative;}</style>').append('head');
//
$('<style>.load.brick div{width: 10px; height: 30px; border-radius:5px; background: black; position: absolute; top: 35px; left: 45px; opacity: 0.05; -webkit-animation: fadeit 1.1s linear infinite; animation: fadeit 1.1s linear infinite;}</style>').append('head');
//
for(var i = 0; i < bar_amount; ++i){
var degree = i / bar_amount * 360;
var delay = i * time_incr;
window.alert('<style>.load.brick div:nth-child(' + (i + 1) + '){ -webkit-transform: rotate(' + degree + 'deg) translate(0, -30px); transform: rotate(' + degree + 'deg) translate(0, -30px); -webkit-animation-delay:' + delay + 's; animation-delay:' + delay + ';</style>');
//
$('<style>.load.brick div:nth-child(' + (i + 1) + '){-webkit-transform: rotate(' + degree + 'deg) translate(0, -30px); transform: rotate(' + degree + 'deg) translate(0, -30px); -webkit-animation-delay:' + delay + 's; animation-delay:' + delay + ';</style>').append('head');
}
var spinner_div = $('<div class="load brick"/>');
for(var i = 0; i < bar_amount; ++i){
spinner_div.append('<div/>');
}
return spinner_div;
}
$(document).ready(function(){
var new_spinner = addSpinner(8, 0.13, 100, 100, 30);
$('body').append(new_spinner);
});
</script>