JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div class="wrapper">
</div>
</body>
CSS
body {
background: #deffff;
}
.wrapper {
background: url('https://upload.wikimedia.org/wikipedia/commons/b/bc/Gluecksklee_(transparent_background).png') top center no-repeat;
width:600px;
height:600px;
}
JavaScript
$(function loop() {
$(".wrapper").animate({temporary_x: 0, temporary_y: 100}, {
duration: 1000,
step: function() {
var position = Math.round(this.temporary_x) + "px " + Math.round(this.temporary_y) + "px";
$(".wrapper").css("background-position", position);
},
complete: function(){
$(".wrapper").animate({temporary_x: 0, temporary_y: 0}, {
duration: 1000,
step: function() {
var position = Math.round(this.temporary_x) + "px " + Math.round(this.temporary_y) + "px";
$(".wrapper").css("background-position", position);
},
complete: function(){
loop();
}
});
}
});
});