jQuery toggleClass example
Toggle class name on click in jQuery
by Sascha
HTML
<div class="progress">
Bla
</div>
CSS
body {
background: white;
padding: 20px;
font-family: Helvetica;
}
@keyframes go-left-right {
from { left: 0; }
to { left: calc(100%); }
}
.progress {
animation: go-left-right 8s infinite alternate;
width: 5%;
top: 0;
position: absolute;
}
JavaScript
$(document).ready(function() {
animateDiv('.progress');
});
function makeNewPosition() {
var h = $(window).height() - 25;
var w = $(window).width() - 25;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh, nw];
}
function animateDiv(myclass) {
var newq = makeNewPosition();
console.log(newq[1], $(window).width());
$(myclass).animate({
top: newq[0],
left: newq[1]
}, 3000, function() {
animateDiv(myclass);
});
}