900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > javascript实现tabs选项卡切换效果(扩展版)【javascript】

javascript实现tabs选项卡切换效果(扩展版)【javascript】

时间:2020-11-05 09:40:17

相关推荐

javascript实现tabs选项卡切换效果(扩展版)【javascript】

web前端|js教程

tabs,选项卡,切换

web前端-js教程

前段时间写了个tabs 选项卡切换效果,今天抽空在原有的基础上进行了扩展,加入了自动轮播,这样就变成了类似图片轮播的效果了。

html 代码:

驱动虚拟按键源码,vscode隐藏代码快捷键,ubuntu 查询内存,tomcat配置可用线程,爬虫进链接,php 前端控制器,济南专业seo推广怎么做lzw

js-tabs

a{color:#a0b3d6;}

.tabs{border:1px solid #a0b3d6;margin:100px;width:300px;}

.tabs-nav a{background:#eaf0fd;line-height:30px;padding:0 20px;display:inline-block;border-right:1px solid #a0b3d6;border-bottom:1px solid #a0b3d6;float:left;}

.tabs-nav .select1,.tabs-nav .select2,.tabs-nav .select3,.tabs-nav .select4{background:white;border-bottom:1px solid white;_position:relative;}

.tabs-content{padding:20px;border-top:1px solid #a0b3d6;margin-top:-1px;}

首页

技术

生活

作品

首页首页首页首页首页首页首页首页首页首页

人声消除 源码,ubuntu启动全是代码,tomcat和阿帕奇的区别,爬虫渗透软件,php后端框架 api,seo搜索引擎优化排名多少钱lzw

技术技术技术技术技术技术技术技术技术技术

大淘宝客源码,小米平板3 ubuntu,关闭tomcat中间件信息,什么是爬虫广告,如何提高php网页打开速度,附子seo解散lzw

生活生活生活生活生活生活生活生活生活生活

作品作品作品作品作品作品作品作品作品作品

11111

22222

33333

11111111111111111111111111111111111

222222222222222222222222222222222222

333333333333333333333333333333333333333

window.onload = function(){

tabs(‘tabs’,’click’,true,1000);

tabs(‘tabs2′,’mouseover’);

}

tabs.js 代码:

function tabs(id,trigger,autoplay,time){

var tabsWrap = document.getElementById(id);

var tabsBtn = tabsWrap.getElementsByTagName(h2)[0].getElementsByTagName(a);

var tabsContent = getClass( abs-content,tabsWrap);

var timer = null;

var current = 0;

show(0);

for(var i = 0,len = tabsBtn.length; i < len; i++){

tabsBtn[i].index = i;

if(trigger == click){

tabsBtn[i].onclick = function(){

show(this.index);

}

}else if(trigger == mouseover){

tabsBtn[i].onmouseover = function(){

show(this.index);

}

}

}

if(autoplay){

autoPlay();

tabsWrap.onmouseover = function(){

clearInterval(timer);

}

tabsWrap.onmouseout = function(){

autoPlay();

}

}

function autoPlay(){

timer = setInterval(function(){

show(current);

current++;

if(current >= tabsBtn.length){

current = 0;

}

},time);

}

function show(n){

current = n;

for(var i = 0,len = tabsBtn.length; i < len; i++){

tabsBtn[i].className = \;

tabsContent[i].style.display = one;

}

tabsBtn[current].className = select + (current + 1);

tabsContent[current].style.display = lock;

}

function getClass(classname,obj){

var results = [];

var elems = obj.getElementsByTagName(*);

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

if(elems[i].className.indexOf(classname) != -1){

results[results.length] = elems[i];

}

}

return results;

}

}

PS:这是本人闲着无聊,通过自己所学的 javascript 知识,随意写的一些效果。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。