Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • js判断是否图片加载完了

    post by onelong / 2009-10-10 18:39 Saturday [javascript]

    <script>
    function SImage(callback){
        var img = new Image();
        this.img = img;
        var appname = navigator.appName.toLowerCase();
        if (appname.indexOf("netscape") == -1){
           //ie
            img.onreadystatechange = function () {
                if (img.readyState == "complete")
                {
                    callback(img);
                }
            };
        } else {
           //firefox
            img.onload = function () {
                if (img.complete == true)
                {
                    callback(img);
                }
            }
        }
    }

    SImage.prototype.get = function (url)
    {
        this.img.src = url;
    }
    var img = new SImage(icall);
    img.get("http://www.xd26.com/photo/up_files/2009-03-27/1238121079Qa5x.jpg");

    function icall(obj){
        alert(obj.width);
    }
    </script>
        img.onload=function(){}可以兼容各种浏览器的

    标签: javascript image
    引用地址:
     

    我要评论