JavaScript插件制作练习-鼠标划过选项卡切换图片

<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
} body {
background: #353131;
} .warp {
position: relative;
top: 50px;
left: 25%;
} ul {
list-style: none;
} ul .warp-li {
float: left;
width: 100px;
height: 40px;
line-height: 40px;
background: #000;
opacity: .3;
color: #fff;
text-align: center;
} ul .warp-li:hover {
background: aquamarine;
color: #000000;
opopacity: 1;
} ul::after {
display: block;
content: "";
clear: both;
} .box {
position: absolute;
left: 0;
top: 40px;
display: none;
} .box img {
width: 500px;
height: 300px;
} #show {
display: block;
} #on {
background: aquamarine;
color: #000;
opopacity: 1;
}
</style>
</head> <body>
<div class="warp">
<ul>
<li class="warp-li" id="on">首页</li>
<li class="warp-li">动漫</li>
<li class="warp-li">游戏</li>
<li class="warp-li">生活</li>
<li class="warp-li">直播</li>
</ul>
<div class="box" id="show">
<img src="img/1.jpg" />
</div>
<div class="box">
<img src="img/18d8bc3eb13533fa3110518aadd3fd1f40345bf4.jpg" />
</div>
<div class="box">
<img src="img/359b033b5bb5c9eab33999fed739b6003bf3b3e1.jpg" />
</div>
<div class="box">
<img src="img/ce4a8e8065380cd7fd58a3eaa944ad3459828123.jpg.png" />
</div>
<div class="box">
<img src="img/timg.jpg" />
</div> </div>
<script type="text/javascript">
(function(window) {
var maxTab = function(tabLen, showLen, tabLenId, showLenId) {
this.tabLen = tabLen;
this.showLen = showLen;
this.tabLenId = tabLenId; //选项卡id
this.showLenId = showLenId; //显示区域id
this.show();//调用切换图片的方法
}
maxTab.prototype = {
constructor: maxTab,
show: function() {
var _this = this; //这里的this是指向maxTab的,function会建里一个作用域所以要保留
var tabLen = document.getElementsByClassName(this.tabLen);
var showLen = document.getElementsByClassName(this.showLen);
var index = 0;
for(var i = 0; i < tabLen.length; i++) {
tabLen[i].setAttribute("index", i);
for(var j = 0; j < tabLen.length; j++) {
tabLen[i].onmouseover= function() {
_this.reset(tabLen);
_this.reset(showLen);
this.id = _this.tabLenId;
index = this.getAttribute("index");
showLen[index].id = _this.showLenId;
}
}
}
},
//格式化id
reset: function(obj) {
for(var i = 0; i < obj.length; i++) {
obj[i].removeAttribute("id");
}
}
}
window.maxTab = maxTab;
})(window) //插件调用
var am = new maxTab("warp-li", "box", "on", "show");
</script>
</body> </html>

JavaScript插件制作-tab选项卡的更多相关文章

  1. :target伪类制作tab选项卡

    :target伪类的作用是突出显示活动的HTML锚,下面是一个简单的例子: HTML代码: <div> <a href="#demo1">点击此处</ ...

  2. 原生javascript 改写的tab选项卡

    <!--css部分--> <style> *{ margin: 0; padding: 0; } ul,li{ list-style: none } .tabbox{ widt ...

  3. 使用jQuery开发tab选项卡插件

    为了复习巩固jQuery的插件开发.HTML和CSS方面的知识,做了一个简单的tab选项卡插件,简单记录一下开发.使用的过程,以备日后使用. 一.插件效果 tab选项卡插件常用的功能均已实现,包括:动 ...

  4. 微信小程序的wx-charts插件-tab选项卡

    微信小程序的wx-charts插件-tab选项卡 效果: //index.js var wxCharts = require('../../utils/wxcharts-min.js'); const ...

  5. 微信小程序swiper制作内容高度不定的tab选项卡

    微信小程序利用swiper制作内容高度不定的tab选项卡,不使用absolute定位,不定高度,由内容自由撑开主要思路是获取内容区的高度来给swiper动态设置值 .wxml <view cla ...

  6. 使用jQuery开发tab选项卡插件(可以右键关闭多个标签)

    在前一篇“使用jQuery开发tab选项卡插件”的基础上添加了tab标签右键关闭菜单功能,菜单主要包括:关闭当前标签.关闭左侧标签.关闭右侧标签.关闭其他.关闭全部. 一.插件效果 二.实现思路 为w ...

  7. javascript插件制作学习-制作步骤

    原生JavaScript插件开发学习 自己制作的demo大家可以看下https://www.cnblogs.com/zimengxiyu/p/9814889.html 插件制作步骤: (一)构造函数 ...

  8. bootstrap 支持的JavaScript插件

    一次性导入: Bootstrap提供了一个单一的文件,这个文件包含了Bootstrap的所有JavaScript插件,即bootstrap.js(压缩版本:bootstrap.min.js). 具体使 ...

  9. Bootstrap JavaScript插件

      在bs3.X中,提供了12种JavaScript插件,分别是:动画过渡(Transition).模态弹窗(Modal).下拉菜单(Dropdown).滚动侦测(Scrollspy).选项卡(Tab ...

随机推荐

  1. JAVA基础:Java中equals和==的区别

    java中的数据类型,可分为两类:  1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boolean    他们之间的比较,应用双等号( ...

  2. SpringBoot中使用Websocket进行消息推送

    WebsocketConfig.java @Configuration public class WebSocketConfig { @Bean public ServerEndpointExport ...

  3. Linux中使用curl命令发送带参数的get请求和post请求

    GET 请求 curl命令 + 请求接口的地址 curl http://**.**.***.**/SeedAgile/SeedApi/querySprintByRequirementNo?parame ...

  4. MapReduce框架中的Shuffle机制

    Shuffle是map和reduce中间的数据调度过程,包括:缓存.分区.排序等. Shuffle数据调度过程: map task处理hdfs文件,调用map()方法,map task的collect ...

  5. C# 递归式快速排序算法

    static void Main(string[] args) { Console.WriteLine("************快速排序*****************"); ...

  6. Clang教程之实现源源变化

    clang教程之实现源源变化 声明:本教程来自于Eli Bendersky's website 原文地址:http://eli.thegreenplace.net/2014/05/01/modern- ...

  7. 13、Nginx七层负载均衡

    1.Nginx负载均衡基本概述 1.1为什么需要使用负载均衡 当我们的Web服务器直接面向用户,往往要承载大量并发请求,单台服务器难以负荷,我使用多台WEB服务器组成集群,前端使用Nginx负载均衡, ...

  8. poj 1953 World Cup Noise (dp)

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16774   Accepted: 8243 ...

  9. office visio

    画 流程图软件 UML 是否要用做类图.时序图?????

  10. 【转载】Java File操作汇总

    转载自博客:https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2Fwww.cnblogs.com%2F 本文通过大量的示例, ...