美文网首页
选项卡封装的函数

选项卡封装的函数

作者: webliweishan | 来源:发表于2017-09-15 21:23 被阅读0次

function tab (id,event,time,isCarrousel) {

var oBox1 = document.getElementById(id);

// 第一个子元素

var oTab = oBox1.children[0];

var aBtn1 = oTab.children;

// 第二个子元素

var oCon = oBox1.children[1];

var aDiv1 = oCon.children;

//下标

var count = 0;

// 延迟调用的timer;

var timer;

for (var i = 0;i < aBtn1.length;i++) {

aBtn1[i].index = i;

//添加事件的地方

aBtn1[i][event] = function () {

// 点击的时候,立马切换,onclick

// 鼠标移入的时候,隔500毫秒,onmouseover

if (event == 'onclick') {

count = this.index;

tab1();

} else {

//将this的值赋值给_this

var _this = this;

timer = setTimeout(function (){

// this -- > btn

count = _this.index;

tab1();

},time);

}

}

aBtn1[i].onmouseout = function () {

clearTimeout(timer);

}

}

if (isCarrousel == 'carrousel') {

//自动播放

var tid = setInterval(nextImg,1000);

oBox1.onmouseover = function () {

clearInterval(tid);

}

oBox1.onmouseout = function () {

clearInterval(tid);

tid = setInterval(nextImg,1000);

}

function nextImg () {

count++;

if (count == aBtn1.length) {

count = 0;

}

tab1();

}

}

//切换选项卡

function tab1 () {

//先清空所有的样式

//先清空所有的样式

for (var j = 0;j < aBtn1.length;j++) {

aBtn1[j].className = '';

aDiv1[j].style.display = 'none';

}

console.log(count);

// 0 1 2 3

// count = undefined

// aBtn1[count]: 获取不到button

aBtn1[count].className = 'active';

aDiv1[count].style.display = 'block';

}

}

window.onload = function () {

//第一个选项卡: 点击切换

tab('box1','onclick',0,'carrousel');

//第二个选项卡: 鼠标移入切换

tab('box2','onmouseover',1000);

}

相关文章

  • 日常封装函数

    // 选项卡封装函数 functiontab(id,event,time,isCarrousel){ // id:...

  • 选项卡封装的函数

    function tab (id,event,time,isCarrousel) { var oBox1 = do...

  • 12.3默写

    封装tab选项卡 拷贝继承 原型继承

  • 小方法

    封装animate 封装each 封装replace 原型链机制数组去重 选项卡 utils() 京东倒计时 京东...

  • 闭包

    包做选项卡 封闭函数

  • python函数的简单封装

    函数的简单封装 实现对文件读写操作的封装 file_function.py(实现函数的封装) (进行函数调用)

  • 代码组织:函数(def)

    代码组织:函数(def) 封装一个功能 封装 容器是对数据的封装函数是对语句的封装类是对方法和属性的封装 函数(f...

  • JS基础案例22-函数练习

    1-100之间的和用函数封装。 函数封装求圆的周长。 函数封装求圆的面积。 函数封装判断2个数,3个数的大小。 判...

  • 原生js 封装选项卡

    要求: 点击,跳转到选项卡2.自动播放3.鼠标放上去时,停止播放4.点击上一个下一个转化5.封装调用函数

  • AJAX 函数封装

    封装函数,采用面向对象的形式封装,用函数包裹,防止空间浪费,函数附带转码功能 自调用函数(function( ){...

网友评论

      本文标题:选项卡封装的函数

      本文链接:https://www.haomeiwen.com/subject/gypesxtx.html