﻿var UpRollPic = {
    o: null,      // 存放滚动的UL
    cloneImg: null,      //克隆UL的第一个图片
    adY: 0,      //滚动值
    distan: 0,     //每个图片的高度
    init: function (obj) {
        if (!obj.style.top) {
            obj.style.top = '0px';
        }
        this.cloneImg = obj.firstChild.cloneNode(true);     //克隆第一个节点
        if (this.cloneImg.nodeType == 3) this.cloneImg = obj.firstChild.nextSibling.cloneNode(true);   //除IE外第一个节点为文本节点,这里做点调整,让克隆节点还是指向第一个元素
        obj.appendChild(this.cloneImg);   //让克隆的节点放入最后
        this.adY = parseInt(obj.style.top);
        this.o = obj;
        this.distan = this.cloneImg.offsetHeight;   //获取高度
        this.moveCtrl();
    },
    moveCtrl:function(){
  if(Math.abs(this.adY) == this.o.offsetHeight - this.distan) this.adY = 0;  //当到达底部,让滚动直接跳回最上面
  if(Math.abs(this.adY)%this.distan==0){
      setTimeout('UpRollPic.moveCtrl()', 2000);   //对每个图片做停留,也就是延迟函数的循环
  } else {
      setTimeout('UpRollPic.moveCtrl()', 10);    //运动循环
  }
  --this.adY;
  UpRollPic.o.style.top = this.adY + 'px';
 }
}//

