css - How to parse a Javascript +random Number into .style.backgroundImage URL -


hi, opinion example. considering me beginner of coding.

i add random number after url gif-file-name.

ex.: turn "intro_animation.gif" "intro_animation.gif?v=7463" number @ end should random each time browser refreshes, animated gif can start again beginning.

i've seen many similar examples on stackoverflow.com, dont know how put parts together

...

here code, don't work. want keep simple possible.

<script> settimeout(function () {     document.getelementbyid("intro").style.backgroundimage = "url('./anim/intro_animation.gif' + ?v= + (math.random() * 1000); )"; }, 0); </script>  <div id="intro" class="intro_animation_gif" style="background-image: url('./anim/intro_animation.gif');"> </div> 

you not far off. make sure put double quotes around parts strings , concatenate pluses.

you might want round random number make sure not contain decimals.

sample:

document.getelementbyid("intro").style.backgroundimage =      "url('./anim/intro_animation.gif?v=" + math.round((math.random() * 1000)) + "')"; 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -