您的位置:首页 > Web前端 > JavaScript

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

2016-06-18 00:17 543 查看
<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>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: