特效介绍
仿阿里巴巴js滑动显示不同内容的tab选项卡特效,共三行两列,滑动上去,就会显示对应的内容。
使用方法
1、在head引入下面的css代码:<style type="text/css"> /*这里定义样式,由于左右滑动区宽度不同,所以代码略多*/ body {margin:0px;border:0px;font-size:12px;background-color:#fff;} a:link{color: #003278;text-decoration: none;} a:visited{color: #003278;text-decoration: none;} a:hover{color: #FF6600;text-decoration: underline;} #slideBox{background:url(images/slideBox_bg.gif);height:168px;width:178px;padding-left:5px;padding-right:5px;} #slide{padding-top:5px} #slide li img{margin-right:3px} #slideBox ul{padding:0;margin:0;clear:both;list-style:none;overflow:hidden} #slideBox li{float:left;font-weight:bold;height:37px !important;height:27px;} #slideBox li a:link,#slideBox li a:visited{color:#000;} #slideBox li a:hover{color:#ff7300;text-decoration: none} #slideBox .l{background:url(images/slideBox_tableft.gif);width:80px;} #slideBox .r{background:url(images/slideBox_tabright.gif);width:94px;float:right} #slideBox .l_h{background:url(images/slideBox_tableft_h.gif);width:80px;} #slideBox .r_h{background:url(images/slideBox_tabright_h.gif);width:94px;float:right;} #slideBox .hide{display:none} #slideBox .l a{width:52px;} #slideBox .r a{width:68px;} .arrow{padding-left:8px;background:url(images/icon_arrow03_right_08x.gif) no-repeat;} #slideBox .l a,#slideBox .r a,#slideBox .l_h a,#slideBox .r_h a{padding-left:24px;display:block;height:100%;padding-top:10px;} .btn_zchy{background:url(images/icon_zchy01_12x.gif) 5px 10px no-repeat;} .btn_cxt{background:url(images/icon_cxt01_12x.gif) 5px 10px no-repeat;} .btn_tggs{background:url(images/icon_tggs01_12x.gif) 5px 10px no-repeat;} .btn_fbxx{background:url(images/icon_fbxx01_12x.gif) 5px 10px no-repeat;} .btn_xzmj{background:url(images/icon_xzmj01_12x.gif) 5px 10px no-repeat;} .btn_alisoft{background:url(images/icon_alisoft01_12x.gif) 5px 10px no-repeat;} /*cont*/ #slideBox .cont_l{float:left;background:url(images/slideBox_conleft.gif);width:157px;height:31px;padding:9px 7px 7px 14px;margin-bottom:4px;overflow:hidden} #slideBox .cont_r{float:left;background:url(images/slideBox_conright.gif);width:157px;height:31px;padding:9px 7px 7px 14px;margin-bottom:4px;overflow:hidden} #slideBox .oneline{line-height:33px;} </style>2、html引入到你需要使用的地方
<div id="slideBox"> <div id="slide"> <ul> <li class="l_h"><a href="http://www.5imoban.net/" class="btn_zchy">注册会员</a></li> <li class="r"><a href="http://www.5imoban.net/" class="btn_cxt">加入诚信通</a></li> </ul> <div class="cont_l" id="sc_1"> 内容一 </div> <div class="hide" id="sc_2"> 内容二 </div> <ul> <li class="l"><a href="http://www.5imoban.net/" class="btn_tggs">推广公司</a></li> <li class="r"><a href="http://www.5imoban.net/" class="btn_fbxx">发布信息</a></li> </ul> <div class="hide" id="sc_3"> 内容三 </div> <div class="hide" id="sc_4"> 内容四 </div> <ul> <li class="l"><a href="http://www.5imoban.net/" class="btn_xzmj">寻找买家</a></li> <li class="r"><a href="http://www.5imoban.net/" class="btn_alisoft">阿里软件</a></li> </ul> <div class="hide" id="sc_5"> 内容五 </div> <div class="hide" id="sc_6"> 内容六 </div> </div> </div>3、js代码放到您的html的</body>的前面:
<script type="text/javascript"> /*alitab author:alicn-wd-ym 这里是所有js实现,代码比较少,主要还是取巧,利用了classname的关系 */ var slideTabIndex=1; var sTabList = document.getElementById("slideBox").getElementsByTagName("li"); for(var i=0;i<sTabList.length;i++){ var obj = sTabList[i].getElementsByTagName("a")[0]; sTabList[i].getElementsByTagName("a")[0].id="slideBtn_"+(i+1); if (obj.addEventListener) { obj.addEventListener( "mouseover", overSlide, false ); } else if (obj.attachEvent) { obj.attachEvent( "onmouseover", overSlide ); } } function overSlide(e){ e = window.event || e; var srcElement = e.srcElement || e.target; var newTabIndex=srcElement.id.replace("slideBtn_",""); var pos = srcElement.parentNode.className; if(newTabIndex==""||pos.indexOf("_h")!=-1)return; document.getElementById("slideBtn_"+slideTabIndex).parentNode.className=document.getElementById("slideBtn_"+slideTabIndex).parentNode.className.replace("_h",""); document.getElementById("sc_"+slideTabIndex).className="hide"; document.getElementById("sc_"+newTabIndex).className="cont_"+pos; srcElement.parentNode.className = pos+"_h"; slideTabIndex=newTabIndex; } <!--slidebox end--> </script>