js操作图片

1 读取图像属性
<img src="image1.jpg" name="myImage">
<a href="#" onClick="window.alert(document.myImage.width)">Width</a>

2 动态加载图像
<script language="JavaScript">
myImage = new Image;
myImage.src = "Tellers1.jpg";
</script>

3 简单的图像替换
<script language="JavaScript">
rollImage = new Image;
rollImage.src = "rollImage1.jpg";
defaultImage = new Image;
defaultImage.src = "image1.jpg";
</script>
<a href="myUrl" onMouseOver="document.myImage.src = rollImage.src;"onMouseOut="document.myImage.src = defaultImage.src;">
<img src="image1.jpg" name="myImage" width=100 height=100 border=0>
</a>

4 随机显示图像
<script language="JavaScript">
var imageList = new Array;
imageList[0] = "image1.jpg";
imageList[1] = "image2.jpg";
imageList[2] = "image3.jpg";
imageList[3] = "image4.jpg";
var imageChoice = Math.floor(Math.random() * imageList.length);
document.write('<img src="’ + imageList[imageChoice] + '">');
</script>

5 函数实现的图像替换
<script language="JavaScript">
var source = 0;
var replacement = 1;
function createRollOver(originalImage,replacementImage) {
var imageArray = new Array;
imageArray[source] = new Image;
imageArray[source].src = originalImage;
imageArray[replacement] = new Image;
imageArray[replacement].src = replacementImage;return imageArray;
}
var rollImage1 = createRollOver("image1.jpg","rollImage1.jpg");
</script>
<a href="#" onMouseOver="document.myImage1.src = rollImage1[replacement].src;"onMouseOut="document.myImage1.src = rollImage1[source].src;">
<img src="image1.jpg" width=100 name="myImage1" border=0>
</a>

6 创建幻灯片

<head>
<script language="JavaScript">
var imageList = new Array;
imageList[0] = new Image;
imageList[0].src = "image1.jpg";
imageList[1] = new Image;imageList[1].src = "image2.jpg";
imageList[2] = new Image;imageList[2].src = "image3.jpg";
imageList[3] = new Image;imageList[3].src = "image4.jpg";
function slideShow(imageNumber) {
document.slideShow.src = imageList[imageNumber].src;
imageNumber += 1;if (imageNumber < imageList.length) {window.setTimeout("slideShow(" + imageNumber + ")",3000);}
}
</script>

</head><body onLoad="slideShow(0)"><img src="image1.jpg" width=100 name="slideShow">

7 随机广告图片
<script language="JavaScript">
var imageList = new Array;
imageList[0] = "image1.jpg";
imageList[1] = "image2.jpg";
imageList[2] = "image3.jpg";
imageList[3] = "image4.jpg";
var urlList = new Array;
urlList[0] = "http://some.host/";
urlList[1] = "http://another.host/";
urlList[2] = "http://somewhere.else/";
urlList[3] = "http://right.here/";
var imageChoice = Math.floor(Math.random() * imageList.length);
document.write('<a href="’ + urlList[imageChoice] + '"><img src="’ + imageList[imageChoice] + '"></a>');
</script>

 

<script language=javascript> 
var im=new Image() 
im.src="http://bbs.51js.com/images/51js.gif" alert(im.fileSize); 
</script> 
<img src="http://bbs.51js.com/images/default/newtopic.gif" name="img1"> 
<script> setTimeout("img1.src=im.src",5000);//你不会看到图片下载的过程 </script>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值