From the past three days, i have been looking to reload a “CSS background-image” each time you click on it. I have not found any relevant answers please help me...
Sorry for my bad english.
From the past three days, i have been looking to reload a “CSS background-image” each time you click on it. I have not found any relevant answers please help me...
Sorry for my bad english.
So you are looking for something like this I assume?
var images = [
'http://placehold.it/500x320/07f',
'http://placehold.it/500x320/f70',
'http://placehold.it/500x320/7f0',
'http://placehold.it/500x320/0f7'
],
i = 0,
n = images.length;
$("#change-image").click(function(){
$("body").css({backgroundImage: "url("+ images[i++ % n] +")" });
});
html, body{height:100%;}
body{
background: red none 50% / cover;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="change-image">CHANGE</button>