JS使用面向对象技术实现的tab选项卡效果示例


Posted in Javascript onFebruary 28, 2017

本文实例讲述了JS使用面向对象技术实现的tab选项卡效果。分享给大家供大家参考,具体如下:

运行效果图如下:

JS使用面向对象技术实现的tab选项卡效果示例

代码如下:

html:

<ul class="scrollUl">
  <li id="m01" class="sd01" value="0"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >新服排期</a></li>
  <li id="m02" class="sd02" value="1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >官方公告</a></li>
</ul>
<div id="c01" style="display: block;">
  <ul>
    <li class="ml10 mt10"><span class="fu"><a title="最三国“群雄逐鹿”震撼开启 敬请期待." class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最三国“群雄逐鹿”震撼开启 ...</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="最三国“群雄逐鹿”震撼开启 敬请期待." class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最三国“群雄逐鹿”震撼开启 ...</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="最三国“群雄逐鹿”震撼开启 敬请期待." class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最三国“群雄逐鹿”震撼开启 ...</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="最三国“群雄逐鹿”震撼开启 敬请期待." class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最三国“群雄逐鹿”震撼开启 ...</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="最三国“群雄逐鹿”震撼开启 敬请期待." class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最三国“群雄逐鹿”震撼开启 ...</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="最三国“群雄逐鹿”震撼开启 敬请期待." class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最三国“群雄逐鹿”震撼开启 ...</a></span><span class="hui9">09-28</span></li>
  </ul>
</div>
<div class="hidden" id="c02" style="display: none;">
  <ul>
    <li class="ml10 mt10"><span class="fu"><a title="《绝地战争》9月8日维护公告" class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《绝地战争》9月8日维护公告</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="《绝地战争》9月8日维护公告" class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《绝地战争》9月8日维护公告</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="《绝地战争》9月8日维护公告" class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《绝地战争》9月8日维护公告</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="《绝地战争》9月8日维护公告" class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《绝地战争》9月8日维护公告</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="《绝地战争》9月8日维护公告" class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《绝地战争》9月8日维护公告</a></span><span class="hui9">09-28</span></li>
    <li class="ml10"><span class="fu"><a title="《绝地战争》9月8日维护公告" class="hei" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《绝地战争》9月8日维护公告</a></span><span class="hui9">09-28</span></li>
   </ul>
</div>

js:

function scrollDoor(){
}
scrollDoor.prototype = {
  sd : function(menus,divs,openClass,closeClass){
    var _this = this;
    if(menus.length != divs.length)
    {
      alert("菜单层数量和内容层数量不一样!");
      return false;
    }
    for(var i = 0 ; i < menus.length ; i++)
    {
      _this.$(menus[i]).value = i;
      _this.$(menus[i]).onmouseover = function(){
        //1.先关闭所有的导航和内容:
        for(var j = 0 ; j < menus.length ; j++)
        {
          _this.$(menus[j]).className = closeClass;
          _this.$(divs[j]).style.display = "none";
        }
        //2.打开当前的导航和内容:
        //_this.$(menus[this.value]).className = openClass;
        this.className = openClass;
        _this.$(divs[this.value]).style.display = "block";
      }
    }
  },
  $ : function(oid){
    if(typeof(oid) == "string")
    return document.getElementById(oid);
    return oid;
  }
}
window.onload = function(){
  var SDmodel = new scrollDoor();
  SDmodel.sd(["m01","m02"],["c01","c02"],"sd01","sd02");
  //SDmodel.sd(["m001","m002"],["c001","c002"],"sd01","sd02");
}

希望本文所述对大家JavaScript程序设计有所帮助。

Javascript 相关文章推荐
jQuery实现自动调整字体大小的方法
Jun 15 Javascript
Jquery-1.9.1源码分析系列(十一)之DOM操作
Nov 25 Javascript
浅析JS运动
Dec 28 Javascript
jQuery插件HighCharts绘制2D金字塔图效果示例【附demo源码下载】
Mar 09 Javascript
Ajax验证用户名或昵称是否已被注册
Apr 05 Javascript
angular过滤器实现排序功能
Jun 27 Javascript
打造通用的匀速运动框架(实例讲解)
Oct 17 Javascript
JS实现的透明度渐变动画效果示例
Apr 28 Javascript
解析Json字符串的三种方法日常常用
May 02 Javascript
vue 实现在函数中触发路由跳转的示例
Sep 01 Javascript
快速解决Vue项目在IE浏览器中显示空白的问题
Sep 04 Javascript
微信小程序实现时间预约功能
Nov 27 Javascript
基于cookie实现zTree树刷新后展开状态不变
Feb 28 #Javascript
js中Number数字数值运算后值不对的解决方法
Feb 28 #Javascript
canvas绘图不清晰的解决方案
Feb 28 #Javascript
jQuery树控件zTree使用方法详解(一)
Feb 28 #Javascript
js数字计算 误差问题的快速解决方法
Feb 28 #Javascript
js数字舍入误差以及解决方法(必看篇)
Feb 28 #Javascript
JS实现浏览器打印、打印预览示例
Feb 28 #Javascript
You might like
PHP简单系统查询模块代码打包下载
2008/06/07 PHP
php选择排序法实现数组排序实例分析
2015/02/16 PHP
PHP基于ip2long实现IP转换整形
2020/12/11 PHP
新浪刚打开页面出来的全屏广告代码
2007/04/02 Javascript
javascript 二分法(数组array)
2010/04/24 Javascript
jQuery替换字符串(实例代码)
2013/11/13 Javascript
探讨JavaScript中声明全局变量三种方式的异同
2013/12/03 Javascript
浏览器缩放检测的js代码
2014/09/28 Javascript
13 款最热门的 jQuery 图像 360 度旋转插件推荐
2014/12/09 Javascript
sails框架的学习指南
2014/12/22 Javascript
Javascript实现div的toggle效果实例分析
2015/06/09 Javascript
JavaScript严格模式详解
2015/11/18 Javascript
详解JavaScript语言的基本语法要求
2015/11/20 Javascript
JavaScript拖拽、碰撞、重力及弹性运动实例分析
2016/01/08 Javascript
原生JS实现拖拽图片效果
2020/08/27 Javascript
jQuery实现字体颜色渐变效果的方法
2017/03/29 jQuery
Chrome调试折腾记之JS断点调试技巧
2017/09/11 Javascript
JS实现常见的查找、排序、去重算法示例
2018/05/21 Javascript
原生js实现抽奖小游戏
2019/06/27 Javascript
javascript 对象 与 prototype 原型用法实例分析
2019/11/11 Javascript
vue使用exif获取图片经纬度的示例代码
2020/12/11 Vue.js
Python生成验证码实例
2014/08/21 Python
python三方库之requests的快速上手
2019/03/04 Python
flask框架jinja2模板与模板继承实例分析
2019/08/01 Python
python代码中怎么换行
2020/06/17 Python
在keras里实现自定义上采样层
2020/06/28 Python
python爬虫中抓取指数的实例讲解
2020/12/01 Python
matplotlib 使用 plt.savefig() 输出图片去除旁边的空白区域
2021/01/05 Python
利用CSS3实现圆角的outline效果的教程
2015/06/05 HTML / CSS
凯撒娱乐:Caesars Entertainment
2018/02/23 全球购物
Yahoo-PHP面试题2
2014/12/06 面试题
《诺贝尔》教学反思
2014/02/17 职场文书
2014年大学生村官工作总结
2014/11/19 职场文书
家长给老师的感谢信
2015/01/20 职场文书
秦兵马俑导游词
2015/02/02 职场文书
个人催款函范文
2015/06/23 职场文书