1.鼠标移入移出切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab切换</title>
<style type="text/css">
* {padding: 0;margin: 0;}
li {list-style: none;}
.wrapper {
margin: 0 auto;
width: 100%;
max-width: 1140px;
}
.tabbox {
margin: 40px auto;
width: 400px;
height: 200px;
border: 1px solid #f70;
overflow: hidden;
}
.tabbox .tab-tit{
position: relative;
height: 40px;
}
ul {
position: absolute;
left: -1px;
width: 401px;
height: 40px;
line-height: 40px;
background-color: #eaeaea;
}
ul li {
float: left;
border-left: 1px solid #f70;
border-bottom: 1px solid #f70;
text-align: center;
width: 99px;
height: 40px;
overflow: hidden;
}
.clear {clear: both;}
.select {
padding-right: 1px;
border-bottom: none;
background-color: #fff;
}
a:link, a:visited {
font-size: 16px;
font-weight: bold;
color: #888;
text-decoration: none;
}
.select a {
color: #333;
}
a:hover, a:active {
color: #f20;
font-weight: bold;
}
.tab-txt {
width: 400px;
padding: 40px;
overflow: hidden;
}
.demo {display: none;}
.tab-txt p {
line-height: 40px;
}
</style>
</head>
<body>
<div class="wrapper">
<div id="tabBox" class="tabbox">
<div id="tabTit" class="tab-tit">
<ul>
<li class="select"><a href="javascript:;">女枪</a></li>
<li><a href="javascript:;">提莫</a></li>
<li><a href="javascript:;">盖伦</a></li>
<li><a href="javascript:;">剑圣</a></li>
</ul>
</div>
<!-- <div class="clear"></div> -->
<div id="tabTxt" class="tab-txt">
<div class="demo" style="display: block;">
<p>我有两把枪,一把叫射,另一把叫,啊~</p>
<p>你有一双迷人的眼睛,我非常喜欢!</p>
</div>
<div class="demo">
<p>我去前面探探路</p>
<p>提莫队长正在待命!</p>
</div>
<div class="demo">
<p>放马过来吧,你会死的很光荣的!</p>
<p>快点儿结束吧,我头有点儿转晕了……</p>
</div>
<div class="demo">
<p>我的剑就是你的剑。</p>
<p>眼睛多,看东西才会更加清楚</p>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function $(id) {
return typeof id === "string" ? document.getElementById(id) : id;
}
window.onload = function() {
var tits = $("tabTit").getElementsByTagName("li");
var txts = $("tabTxt").getElementsByClassName("demo");
if(tits.length != txts.length) {return;}
for(var i=0,l=tits.length; i<l; i++) {
tits[i].id = i;
tits[i].onmouseover = function() {
for(var j=0; j<l; j++) {
tits[j].className = "";
txts[j].style.display = "none";
}
this.className = "select";
txts[this.id].style.display = "block";
}
}
}
</script>
</body>
</html>
2.鼠标移入移出延时切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab切换之延时切换</title>
<style type="text/css">
* {padding: 0;margin: 0;}
li {list-style: none;}
.wrapper {
margin: 0 auto;
width: 100%;
max-width: 1140px;
}
.tabbox {
margin: 40px auto;
width: 400px;
height: 200px;
border: 1px solid #f70;
overflow: hidden;
}
.tabbox .tab-tit{
position: relative;
height: 40px;
}
ul {
position: absolute;
left: -1px;
width: 401px;
height: 40px;
line-height: 40px;
background-color: #eaeaea;
}
ul li {
float: left;
border-left: 1px solid #f70;
border-bottom: 1px solid #f70;
text-align: center;
width: 99px;
height: 40px;
overflow: hidden;
}
.clear {clear: both;}
.select {
padding-right: 1px;
border-bottom: none;
background-color: #fff;
}
a:link, a:visited {
font-size: 16px;
font-weight: bold;
color: #888;
text-decoration: none;
}
.select a {
color: #333;
}
a:hover, a:active {
color: #f20;
font-weight: bold;
}
.tab-txt {
width: 400px;
padding: 40px;
overflow: hidden;
}
.demo {display: none;}
.tab-txt p {
line-height: 40px;
}
</style>
</head>
<body>
<div class="wrapper">
<div id="tabBox" class="tabbox">
<div id="tabTit" class="tab-tit">
<ul>
<li class="select"><a href="javascript:;">女枪</a></li>
<li><a href="javascript:;">提莫</a></li>
<li><a href="javascript:;">盖伦</a></li>
<li><a href="javascript:;">剑圣</a></li>
</ul>
</div>
<!-- <div class="clear"></div> -->
<div id="tabTxt" class="tab-txt">
<div class="demo" style="display: block;">
<p>我有两把枪,一把叫射,另一把叫,啊~</p>
<p>你有一双迷人的眼睛,我非常喜欢!</p>
</div>
<div class="demo">
<p>我去前面探探路</p>
<p>提莫队长正在待命!</p>
</div>
<div class="demo">
<p>放马过来吧,你会死的很光荣的!</p>
<p>快点儿结束吧,我头有点儿转晕了……</p>
</div>
<div class="demo">
<p>我的剑就是你的剑。</p>
<p>眼睛多,看东西才会更加清楚</p>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function $(id) {
return typeof id === "string" ? document.getElementById(id) : id;
}
window.onload = function() {
var timer = null;
var tits = $("tabTit").getElementsByTagName("li");
var txts = $("tabTxt").getElementsByClassName("demo");
if(tits.length != txts.length) {return;}
for(var i=0,l=tits.length; i<l; i++) {
tits[i].id = i;
tits[i].onmouseover = function() {
var that = this;
if(timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(function() {
for(var j=0; j<l; j++) {
tits[j].className = "";
txts[j].style.display = "none";
}
that.className = "select";
txts[that.id].style.display = "block";
},500);
}
}
}
</script>
</body>
</html>
3. tab自动切换,鼠标移入移出立即切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab切换之自动切换</title>
<style type="text/css">
* {padding: 0;margin: 0;}
li {list-style: none;}
.wrapper {
margin: 0 auto;
width: 100%;
max-width: 1140px;
}
.tabbox {
margin: 40px auto;
width: 400px;
height: 200px;
border: 1px solid #f70;
overflow: hidden;
}
.tabbox .tab-tit{
position: relative;
height: 40px;
}
ul {
position: absolute;
left: -1px;
width: 401px;
height: 40px;
line-height: 40px;
background-color: #eaeaea;
}
ul li {
float: left;
border-left: 1px solid #f70;
border-bottom: 1px solid #f70;
text-align: center;
width: 99px;
height: 40px;
overflow: hidden;
}
.clear {clear: both;}
.select {
padding-right: 1px;
border-bottom: none;
background-color: #fff;
}
a:link, a:visited {
font-size: 16px;
font-weight: bold;
color: #888;
text-decoration: none;
}
.select a {
color: #333;
}
a:hover, a:active {
color: #f20;
font-weight: bold;
}
.tab-txt {
width: 400px;
padding: 40px;
overflow: hidden;
}
.demo {display: none;}
.tab-txt p {
line-height: 40px;
}
</style>
</head>
<body>
<div class="wrapper">
<div id="tabBox" class="tabbox">
<div id="tabTit" class="tab-tit">
<ul>
<li class="select"><a href="javascript:;">女枪</a></li>
<li><a href="javascript:;">提莫</a></li>
<li><a href="javascript:;">盖伦</a></li>
<li><a href="javascript:;">剑圣</a></li>
</ul>
</div>
<!-- <div class="clear"></div> -->
<div id="tabTxt" class="tab-txt">
<div class="demo" style="display: block;">
<p>我有两把枪,一把叫射,另一把叫,啊~</p>
<p>你有一双迷人的眼睛,我非常喜欢!</p>
</div>
<div class="demo">
<p>我去前面探探路</p>
<p>提莫队长正在待命!</p>
</div>
<div class="demo">
<p>放马过来吧,你会死的很光荣的!</p>
<p>快点儿结束吧,我头有点儿转晕了……</p>
</div>
<div class="demo">
<p>我的剑就是你的剑。</p>
<p>眼睛多,看东西才会更加清楚</p>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function $(id) {
return typeof id === "string" ? document.getElementById(id) : id;
}
window.onload = function() {
var index = 0;
var timer = null;
var tits = $("tabTit").getElementsByTagName("li");
var txts = $("tabTxt").getElementsByClassName("demo");
if(tits.length != txts.length) {return;}
for(var i=0,l=tits.length; i<l; i++) {
tits[i].id = i;
tits[i].onmouseover = function() {
clearInterval(timer);
styleFun(this.id);
}
tits[i].onmouseout = function() {
timer = setInterval(autoPlay, 2000);
}
}
//在开启定时器的同时清楚定时器并置空
if(timer) {
clearInterval(timer);
timer = null;
}
timer = setInterval(autoPlay, 2000);
function autoPlay() {
index++;
if(index >= tits.length) {
index = 0;
}
styleFun(index);
}
function styleFun(ele) {
for(var j=0,m=tits.length; j<m; j++) {
tits[j].className = "";
txts[j].style.display = "none";
}
tits[ele].className = "select";
txts[ele].style.display = "block";
//将鼠标移入移出时的index传给autoPlay;
index = ele;
}
}
</script>
</body>
</html>
4. 广告栏切换实例
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
.wrap {
height: 170px;
width: 490px;
margin: 20px auto;
overflow: hidden;
position: relative;
margin: 100px auto;
}
.wrap ul {
position: absolute;
}
.wrap ul li {
height: 170px;
}
.wrap ol {
position: absolute;
right: 5px;
bottom: 10px;
}
.wrap ol li {
height: 20px;
width: 20px;
background: #ccc;
border: solid 1px #666;
margin-left: 5px;
color: #000;
float: left;
line-height: center;
text-align: center;
cursor: pointer;
}
.wrap ol .on {
background: #E97305;
color: #fff;
}
</style>
<script type="text/javascript">
window.onload = function() {
var wrap = document.getElementById('wrap'),
pic = document.getElementById('pic'),
piclist = pic.getElementsByTagName('li'),
list = document.getElementById('list').getElementsByTagName('li'),
picheight = 170,
index = 0,
timer = null;
if(piclist.length != list.length) {
return;
}
// 定义并调用自动播放函数
if(timer) {
clearInterval(timer);
timer = null;
}
timer = setInterval(picFunc, 2000);
function picFunc() {
index++;
if(index >= piclist.length) {
index = 0;
}
changePic(index);
}
// 定义图片切换函数
function changePic(ele) {
for(var j = 0, m = piclist.length; j < m; j++) {
list[j].className = "";
}
pic.style.top = -ele * picheight + "px";
list[ele].className = "on";
index = ele;
}
// 鼠标划过整个容器时停止自动播放
wrap.onmouseover = function() {
clearInterval(timer);
}
// 鼠标离开整个容器时继续播放至下一张
wrap.onmouseout = function() {
timer = setInterval(picFunc, 2000);
}
// 遍历所有数字导航实现划过切换至对应的图片
for(var i = 0, l = list.length; i < l; i++) {
list[i].id = i;
list[i].onmouseover = function() {
changePic(this.id);
}
}
}
</script>
</head>
<body>
<div class="wrap" id='wrap'>
<ul id="pic">
<li><img src="http://img.mukewang.com/54111cd9000174cd04900170.jpg" alt=""></li>
<li><img src="http://img.mukewang.com/54111dac000118af04900170.jpg" alt=""></li>
<li><img src="http://img.mukewang.com/54111d9c0001998204900170.jpg" alt=""></li>
<li><img src="http://img.mukewang.com/54111d8a0001f41704900170.jpg" alt=""></li>
<li><img src="http://img.mukewang.com/54111d7d00018ba604900170.jpg" alt=""></li>
</ul>
<ol id="list">
<li class="on">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</div>
</body>
</html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
# tab切换
# 微信小程序 swiper制作tab切换实现附源码
# js中常用的Tab切换效果(推荐)
# jquery实现简单Tab切换菜单效果
# 最简单的tab切换实例代码
# Android App中制作仿MIUI的Tab切换效果的实例分享
# jQuery+css实现的tab切换标签(兼容各浏览器)
# javascript实现tab切换的两个实例
# javascript实现tab切换的四种方法
# jquery实现初次打开有动画效果的网页TAB切换代码
# jQuery实现带延迟的二级tab切换下拉列表效果
# 鼠标
# 我有
# 才会
# 我去
# 你有
# 来吧
# 移出
# 会死
# 把枪
# 盖伦
# 剑圣
# 自动播放
# 遍历
# 下一张
# eaeaea
# float
# bottom
# align
# center
# ul
相关文章:
如何彻底删除建站之星生成的Banner?
建站之星安装后如何配置SEO及设计样式?
网站制作软件有哪些,制图软件有哪些?
巅云智能建站系统:可视化拖拽+多端适配+免费模板一键生成
已有域名如何免费搭建网站?
如何快速查询网站的真实建站时间?
如何在Windows服务器上快速搭建网站?
,在苏州找工作,上哪个网站比较好?
网站好制作吗知乎,网站开发好学吗?有什么技巧?
如何用美橙互联一键搭建多站合一网站?
建站VPS能否同时实现高效与安全翻墙?
建站之星如何一键生成手机站?
深圳企业网站制作设计,在深圳如何网上全流程注册公司?
广州营销型建站服务商推荐:技术优势与SEO优化解析
Thinkphp 中 distinct 的用法解析
再谈Python中的字符串与字符编码(推荐)
小米网站链接制作教程,请问miui新增网页链接调用服务有什么用啊?
网站视频制作书签怎么做,ie浏览器怎么将网站固定在书签工具栏?
如何在腾讯云免费申请建站?
矢量图网站制作软件,用千图网的一张矢量图做公司app首页,该网站并未说明版权等问题,这样做算不算侵权?应该如何解决?
如何快速搭建高效香港服务器网站?
网站制作报价单模板图片,小松挖机官方网站报价?
如何打造高效商业网站?建站目的决定转化率
网站制作说明怎么写,简述网页设计的流程并说明原因?
建站与域名管理如何高效结合?
焦点电影公司作品,电影焦点结局是什么?
专业网站制作企业网站,如何制作一个企业网站,建设网站的基本步骤有哪些?
如何用PHP快速搭建CMS系统?
详解jQuery中基本的动画方法
如何快速搭建高效WAP手机网站?
如何用景安虚拟主机手机版绑定域名建站?
弹幕视频网站制作教程下载,弹幕视频网站是什么意思?
视频网站制作教程,怎么样制作优酷网的小视频?
高端建站如何打造兼具美学与转化的品牌官网?
python的本地网站制作,如何创建本地站点?
香港服务器如何优化才能显著提升网站加载速度?
可靠的网站设计制作软件,做网站设计需要什么样的电脑配置?
网站制作难吗安全吗,做一个网站需要多久时间?
电商网站制作公司有哪些,1688网是什么意思?
北京网站制作网页,网站升级改版需要多久?
如何快速上传建站程序避免常见错误?
如何在服务器上配置二级域名建站?
建站之星IIS配置教程:代码生成技巧与站点搭建指南
为什么Go需要go mod文件_Go go mod文件作用说明
如何通过cPanel快速搭建网站?
代刷网站制作软件,别人代刷火车票靠谱吗?
,购物网站怎么盈利呢?
,怎么在广州志愿者网站注册?
南平网站制作公司,2025年南平市事业单位报名时间?
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
*请认真填写需求信息,我们会在24小时内与您取得联系。