Sample code for implementing Tab switching effect using JS

黄舟
Release: 2017-10-21 09:58:39
Original
2344 people have browsed it

html part


css part


*{ padding:0px; margin:0px; list-style: none; font-size: 14px; } #tab{ width:298px; height:120px; margin:10px; border:1px solid #eee; overflow: hidden; } .tab-nav{ width:400px; position:relative; height:27px; } .tab-nav ul{ position:absolute; width:301px; left:-1px; background-color: #f7f7f7; } .tab-nav li{ float:left; width:58px; padding: 0 1px; height:36px; background-color: #f7f7f7; border-bottom: 1px solid #eee; text-align: center; } .tab-nav li.active{ background-color: #fff; border-bottom-color:#fff; border-left: 1px solid #eee; border-right: 1px solid #eee; padding:0px; font-weight: bolder; } li a:link,li a:visited{ text-decoration: none; color:#000; } #tab-contain .mod{ margin:25px 6px 10px 6px; } #tab-contain .mod ul li{ float: left; width:143px; height:25px; overflow: hidden; }
Copy after login

Js part


function $(id){ return typeof id==='string'?document.getElementById(id):id; } window.onload=function(){ var navs=$('tab-nav').getElementsByTagName('li'); var ps=$('tab-contain').getElementsByTagName('p'); // alert(ps.length); if(navs.length!=ps.length){ return; } for(var i=0;i
        
Copy after login

The above is the detailed content of Sample code for implementing Tab switching effect using JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!