src/lay/modules/layer.js
function loadImage(url, callback, error) {   
    var img = new Image();
    img.src = url; 
    if(img.complete){
      return callback(img);
    }
    img.onload = function(){
      img.onload = null;
      callback(img);
    };
    img.onerror = function(e){
      img.onerror = null;
      error(e);
    };  
  }
function loadImage(url, callback, error) {   
    var img = new Image();
    img.src = url; 
    if(img.complete){
      return callback(img);
    }
    img.onload = function(){
      img.onload = null;
      callback(img);
    };
    img.onerror = function(e){
      img.onerror = null;
      error(e);
    };  
  }
function loadImage ( url , callback , error ) { var img = new Image ( ) ; img . src = url ; if ( img . complete ) { return callback ( img ) ; } img . onload = function ( ) { img . onload = null ; callback ( img ) ; } ; img . onerror = function ( e ) { img . onerror = null ; error ( e ) ; } ; }
图片预加载
图片预加载