JavaScript方法和技巧大全——图像
2010-09-14 13:39:58 来源:WEB开发网函数实现的图像替换1<script language=”JavaScript”>
2 var source = 0;
3 var replacement = 1;
4 function createRollOver(originalImage,replacementImage) {
5 var imageArray = new Array;
6 imageArray[source] = new Image;
7 imageArray[source].src = originalImage;
8 imageArray[replacement] = new Image;
9 imageArray[replacement].src = replacementImage;
10 return imageArray;
11 }
12 var rollImage1 = createRollOver(“image1.jpg”,”rollImage1.jpg”);
13</script>
14 <a href=”#” onMouseOver=”document.myImage1.src = rollImage1[replacement].src;”
15 onMouseOut=”document.myImage1.src = rollImage1[source].src;”>
16 <img src=http://tech.ddvip.com/2009-02/"/”image1.jpg"” width=100 name=”myImage1” border=0>
17 </a>
创建幻灯片1<script language=”JavaScript”>
2 var imageList = new Array;
3 imageList[0] = new Image;
4 imageList[0].src = “image1.jpg”;
5 imageList[1] = new Image;
6 imageList[1].src = “image2.jpg”;
7 imageList[2] = new Image;
8 imageList[2].src = “image3.jpg”;
9 imageList[3] = new Image;
10 imageList[3].src = “image4.jpg”;
11 function slideShow(imageNumber) {
12 document.slideShow.src = imageList[imageNumber].src;
13 imageNumber += 1;
14 if (imageNumber < imageList.length) {
15 window.setTimeout(“slideShow(“ + imageNumber + “)”,3000);
16 }
17 }
18</script>
19 </head>
20 <body onLoad=”slideShow(0)”>
21 <img src=http://tech.ddvip.com/2009-02/"/”image1.jpg"” width=100 name=”slideShow”>
随机广告图片
1<script language=”JavaScript”>
2 var imageList = new Array;
3 imageList[0] = “image1.jpg”;
4 imageList[1] = “image2.jpg”;
5 imageList[2] = “image3.jpg”;
6 imageList[3] = “image4.jpg”;
7 var urlList = new Array;
8 urlList[0] = “http://some.host/”;
9 urlList[1] = “http://another.host/”;
10 urlList[2] = “http://somewhere.else/”;
11 urlList[3] = “http://right.here/”;
12 var imageChoice = Math.floor(Math.random() * imageList.length);
13 document.write(‘<a href=”’ + urlList[imageChoice] + ‘“><img src=”’ + imageList[imageChoice] + ‘“></a>’);
14</script>
Tags:JavaScript 方法 技巧
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接