主题:求图片自动变换的效果实现
csover
[专家分:1010] 发布于 2007-06-18 15:31:00
从实现库读取几张图片,放在同一个<img>里头,如何运用JS来实现图片在规定的时间内自动变换下一张!这种效果有没有人实现过?能给些源码进行参考或者网址也行!谢谢!
回复列表 (共1个回复)
沙发
mdwboy [专家分:410] 发布于 2007-06-18 16:06:00
js代码如下:
var flag=false;
function DrawImage(ImgD,h,w){
var image=new Image();
var iwidth = w; //定义允许图片宽度
var iheight = h; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
调用上面的JS
<img onload="DrawImage(this,250,250)">
我来回复