码迷,mamicode.com
首页 > Web开发 > 详细

JS 基于面向对象的 轮播图2

时间:2016-06-18 01:19:48      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

<script>

// 函数不能重名, --> 子函数
// is defined function --> 函数名是否写错了
function AutoTab(id) {
    Tab.apply(this, arguments);
    this.timer = null;
    this.inits();
    // this.autoPlay();
}

AutoTab.prototype = new Tab();
AutoTab.prototype.constructor = AutoTab;

// 初始化
AutoTab.prototype.inits = function () {
    this.play();
    this.over();
    this.out();
};

// 自动播放
AutoTab.prototype.play = function(){
    var _this = this;
    this.timer = setInterval(function(){
        _this.iNow++;
        if(_this.iNow==_this.aBtn.length){
            _this.iNow = 0;
        }
        _this.tab();
    },1000);
};
// 停止
AutoTab.prototype.stop = function () {
    clearInterval(this.timer);
};
// 鼠标经过
AutoTab.prototype.over = function () {
    var _this = this;
    this.oBox.onmouseover = function () {
        _this.stop();
    };
};
// 鼠标离开
AutoTab.prototype.out = function () {
    var _this = this;
    this.oBox.onmouseout = function () {
        _this.play();
    };
};

window.onload=function(){
    new Tab(‘tab1‘);
    new AutoTab(‘tab2‘);
};

</script>

  

JS 基于面向对象的 轮播图2

标签:

原文地址:http://www.cnblogs.com/zsongs/p/5595480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!