jQuery toggleClass example
Toggle class name on click in jQuery
by Sascha
HTML
<img src="https://www.svgimages.com/svg-image/s10/sample-barcode-256x256.png" class="progress">
CSS
@keyframes go-left-right {
from {
left: 0;
}
to {
left: calc(100%);
transform: scale(-1, 1);
}
}
.progress {
animation: go-left-right 8s infinite alternate;
width: 5%;
top: 0;
position: absolute;
}
JavaScript
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();
$(myclass).animate({
top: newq[0],
left: newq[1]
}, 3000, function() {
animateDiv(myclass);
});
}
animateDiv('.progress');