javascript - Change background-image of a div everytime page refresh -
according i've seen in internet should able change background-image of div everytime page refresh javascript script. it's not working reason. appreciated.
this html
<div class="home-intro show-for-medium-up" id="home-intro"> </div>
this css
.home-intro{ background-image: url("../images/1.png"); background-color:grey; height:500px; color:$white; text-align:center; }
this js
<script> function randomimage(){ var images = [ '../images/1.png', '../images/2.png', '../images/3.png']; var size = images.length; var x = math.floor(size * math.random()); console.log(x); var element = document.getelementsbyclassname('home-intro'); console.log(element); element[0].style["background-image"] = "url("+ images[x] + ") no-repeat;"; } document.addeventlistener("domcontentloaded", randomimage);
the issue trying set no-repeat attribute of background-image
property. no-repeat attribute of background
property.
Comments
Post a Comment