首页 > Web开发 > 详细

JS 随机图片效果

时间:2015-05-27 02:18:54      阅读:316      评论:0      收藏:0      [点我收藏+]
<html>
<head>
<title>JS 随机图片效果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
img {  border: #999999; 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 = "demo1.png";
images[2] = new Image();
images[2].src = "demo2.png";
images[3] = new Image();
images[3].src = "demo3.png";
images[4] = new Image();
images[4].src = "demo4.png";

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="demo1.png">
</body>
</html>

?

效果图:
bubuko.com,布布扣
?

?

JS 随机图片效果

原文:http://onestopweb.iteye.com/blog/2214459

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!