1//使用 

  var t1=new Tab({
etype:'onmou',//默认点击触发,如果事件写错了,当作单击
autoplay:2000,//有时间值(按照事件自动播放)和false(不自动播放)
invoke:3,//默认是第一项。
});

 
//插件的基本结构
;(function(){
function Tab(options){//options:配置参数
this.tab=document.querySelector('.tab');
this.tabBtn=document.querySelector('.tab_btn');
this.btns=this.tabBtn.getElementsByTagName('li');
this.divs=this.tab.querySelectorAll('.tab_item');
this.num=0;
this.timer=null;
this.options=options;
this.settings={//默认参数
etype:'onclick',//默认点击触发,如果事件写错了,当作单击
autoplay:3000,//有时间值(按照事件自动播放)和false(不自动播放)
invoke:1,//默认是第一项。
effect:'display'//display/opacity
}
this.init();
} Tab.prototype.init=function(){
var that=this;
extend(this.settings,this.options);
if(this.settings.etype=='onclick' || this.settings.etype!='onmouseover'){
this.tabSwitch('onclick');
}else if(this.settings.etype=='onmouseover'){
this.tabSwitch(this.settings.etype);
}
if(this.settings.autoplay){//如果配置参数传入一个时间,允许自动轮播,轮播的时间传过去
this.autoplay(this.settings.autoplay);
}
if(this.settings.invoke>1 && this.settings.invoke<=this.btns.length){
this.num=this.settings.invoke-1;
this.tabchange();
}
this.tab.onmouseover=function(){
clearInterval(that.timer);
}
this.tab.onmouseout=function(){
that.autoplay(that.settings.autoplay);
}
} Tab.prototype.tabSwitch=function(e){
var that=this;
for(var i=0;i<this.btns.length;i++){
this.btns[i].index=i;
this.btns[i][e]=function(){
that.num=this.index;
that.tabchange();
}
}
}
Tab.prototype.tabchange=function(){
for(var i=0;i<this.btns.length;i++){
this.btns[i].className='';
this.divs[i].className='hide';
if(this.settings.effect=='opacity'){
buffermove(this.divs[i],{opacity:0});
this.divs[i].style.display='none';
}
}
this.btns[this.num].className='active';
if(this.settings.effect=='display' || this.settings.effect!='opacity'){
this.divs[this.num].className='show';
}else if(this.settings.effect=='opacity'){
this.divs[this.num].style.display='block';
buffermove(this.divs[this.num],{opacity:100});
}
}
Tab.prototype.autoplay=function(time){
var that=this;
this.timer=setInterval(function(){
that.num++;
if(that.num>=that.btns.length){
that.num=0;
}
that.tabchange();
},time);
} function extend(obj1,obj2){
for(var i in obj2){
obj1[i]=obj2[i];
}
return obj1;
}
window.Tab=Tab;
})();

一个小的tab切换插件的更多相关文章

  1. jquery做一个小的轮播插件---有BUG,后续修改

    //首页无缝轮播 ; (function($, window, document, undefined) { $.fn.slider = function(options) { var default ...

  2. 微信小程序tab切换,可滑动切换,导航栏跟随滚动实现

    简介 看到今日头条小程序页面可以滑动切换,而且tab导航条也会跟着滚动,点击tab导航,页面滑动,切导航栏也会跟着滚动,就想着要怎么实现这个功能 像商城类商品类目如果做成左右滑动切换类目用户体验应该会 ...

  3. iTabs Tab切换插件

    最近项目中使用到Tab切换,切换的页面不变,内容发生变化,随手写了份简单的插件,附带源码.先看样子: 本人也考虑到是否使用jquery ui tab,但是还是热衷于自己写一份,首先好处之一是易于培训, ...

  4. 根据id来实现小程序tab切换,

    本例根据绑定id来实现tab切换,但本例仍有缺陷,用for循环数据,无法实现切换.如有大神能够有更好方法,欢迎留言更正 WXML: <view class="tab"> ...

  5. 编写tab切换插件

    html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  6. 小程序tab切换 点击左右滑动

    wxml <scroll-view scroll-x="true" class="navbar-box"> <block wx:for=&qu ...

  7. 关于一个页面的tab切换整体页面刷新而tab标签处是同一个文件怎么做焦点的问题

    解决方法,不能直接写点击效果就要在超链接中加一个参数,根据参数的值去给变焦点的效果,实现方法如下: <div class="vip_search">           ...

  8. 从一个简单的Tab切换开始——与AJAX的结合

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 小程序——Tab切换

    <view class="body"> <view class="nav bc_white"> <view class=" ...

随机推荐

  1. ios开发常用RGB色值

    iOS中RGB常用的色值,同时可将对颜色的设置定义成宏,方便开发应用,如: // RGB颜色转换(16进制->10进制) #define UIColorFromRGB(rgbValue) [UI ...

  2. golang GET 出现 x509: certificate signed by unknown authority

    我们编写一个Go程序来尝试与这个HTTPS server建立连接并通信. //gohttps/4-https/client1.gopackage main import (    "fmt& ...

  3. php常用面试知识点

    1.php基础 2.mysql基础 3.js基础 4.jq 5.正则 6.面向对象 7.分页类,购物车类,数据库类,上传类,图片处理类 8.smarty模板技术(以及自己写模板引擎) 9.ajax 1 ...

  4. Maven常用命令及在Eclipse中的应用

    1.常用命令 mvn archetype:generate--构建项目 mvn clean--项目清理 mvn test--项目单元测试的编译 mvn compile--项目源代码的编译 mvn pa ...

  5. Python数据结构之四——set(集合)

    Python版本:3.6.2  操作系统:Windows  作者:SmallWZQ 经过几天的回顾和学习,我终于把Python 3.x中的基础知识介绍好啦.下面将要继续什么呢?让我想想先~~~嗯,还是 ...

  6. 关于HTTP,你知道哪些?

    HTTP简介 HTTP 的全称是 Hypertext Transfer Protocol,超文本传输协议 规定客户端和服务器之间的数据传输格式 让客户端和服务器能有效地进行数据沟通 HTTP 协议是网 ...

  7. python——Django项目模板

    views.py # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.shortcuts impor ...

  8. HDU - 2187 贪心

    思路:  按照单价升序排序,依次买就行. AC代码 #include <cstdio> #include <cmath> #include <algorithm> ...

  9. 用Node.JS+MongoDB搭建个人博客(页面模板)(五)(结束)

    <差不多先生> 我是差不多先生,我的差不多是天生.也代表我很天真,也代表我是个闲人.这差不多的人生,总是见缝插针. 求学的道路上总是孤独的,即使别人不理解我,认为我是奇葩!但没关系,我会坚 ...

  10. 【前端】Vue2全家桶案例《看漫画》之二、完成首页基本样式

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_2.html 项目github地址:https://github.com/shamoyuu/ ...