This article describes the random display of image effects when JS implements page loading. Share it for your reference, as follows:
<html><head><title>JS Random Image Effect</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css"><!--img { border: #99999; border-style: dotted; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}--></style></head><SCRIPT LANGUAGE="JavaScript">var rand1 = 0;var useRand = 0;images = new Array;images[1] = new Image();images[1].src = "img/a1.jpg";images[2] = new Image();images[2].src = "img/a2.jpg";images[3] = new Image();images[3].src = "img/a3.jpg";images[4] = new Image();images[4].src = "img/a4.jpg";function swapPic() {var imgnum = images.length - 1;do {var randnum = Math.random();rand1 = Math.round((imgnum - 1) * randnum) + 1;} while (rand1 == useRand);useRand = rand1;document.randimg.src = images[useRand].src;}</script><body bgcolor="#FFFFFF" text="#000000" OnLoad="swapPic()"><img name="randimg" src="img/a1.jpg"></body></html>The code is tested and runs normally. I will no longer have the running renderings here. Interested friends can choose a few pictures of beautiful women to test them to see the effect.
For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Traversal Algorithm and Skills", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills" and "Summary of JavaScript Mathematical Operation Usage"
I hope this article will be helpful to everyone's JavaScript programming.