RE: How to change body background with image by javascript?

html body background change

Rudradeep Senior Developer Asked on January 23, 2017 in PHP.
Add Comment
1 Answers

Put the java script between head tag.Create a folder “images” and keep all the images in that folder

<title>Change body background</title>
<script type="text/javascript">
var picPaths = [‘images/pic1.jpg’,’images/pic2.jpg’,’images/pic3.jpg’,’images/pic4.jpg’];
var oPics = [];
for(i=0; i < picPaths.length; i++){
oPics[i] = new Image();
oPics[i].src = picPaths[i];
curPic = Math.floor(Math.random()*oPics.length);
document.getElementById(‘imgRotator’).src = oPics[curPic].src;
<img id="imgRotator" src="" alt="" height="470" width="600"/>
Team Leader Answered on March 19, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.