 var step = 1; //每次走动的像素
 var speed = 30; //图片浮动速度，数值越大，速度越慢（建议设置为30-100之间）
 var collection;
 var id="img1";
 function floaters_move() {
   this.items    = [];
   this.addItem  = function() {
    
    var newItem = {};
    //debugger;
    newItem.object = document.getElementById(id);
    newItem.xPos = 0;
    newItem.yPos = 0;
    newItem.xon = 0;
    newItem.yon = 0;
    this.items = newItem;
   }
   this.play = function() {
    collection = this.items
    setInterval('move_play()',speed);
   }
 }
         function move_play() {
   
    var followObj        = collection.object;
    var followObj_x        = followObj.offsetWidth;
    var followObj_y        = followObj.offsetHeight;
    
    followObj.style.left = collection.xPos + document.documentElement.scrollLeft+'px';
    followObj.style.top = collection.yPos + document.documentElement.scrollTop+'px';
    if(collection.xon) {
     collection.xPos += step;
    } else {
     collection.xPos -= step;
    }
    if(collection.yon) {
     collection.yPos += step;
    } else {
     collection.yPos -= step;
    }
    if(collection.xPos >= (document.documentElement.clientWidth-followObj_x)) {
    
     collection.xon = 0;
     collection.xPos = document.documentElement.clientWidth-followObj_x;
    }
    if(collection.xPos < 0) {
     collection.xon = 1;
     collection.xPos = 0;
    }
    if(collection.yPos >= (document.documentElement.clientHeight-followObj_y)) {
     collection.yon = 0;
     collection.yPos = document.documentElement.clientHeight-followObj_y;
    }
    if(collection.yPos < 0) {
     collection.yon = 1;
     collection.yPos = 0;
    }
   
 }
 var theFloaters_move        = new floaters_move();
 theFloaters_move.addItem();
 theFloaters_move.play();
