回 帖 发 新 帖 刷新版面

主题:求图片自动变换的效果实现

从实现库读取几张图片,放在同一个<img>里头,如何运用JS来实现图片在规定的时间内自动变换下一张!这种效果有没有人实现过?能给些源码进行参考或者网址也行!谢谢!

回复列表 (共1个回复)

沙发

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)">

我来回复

您尚未登录,请登录后再回复。点此登录或注册