首頁  >  文章  >  web前端  >  JS CSS實作自動切換的網頁滑動門選單效果程式碼_javascript技巧

JS CSS實作自動切換的網頁滑動門選單效果程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 15:39:231544瀏覽

本文實例講述了JS CSS實現自動切換的網頁滑動門選單效果代碼。分享給大家供大家參考。具體如下:

這是一款支援自動切換功能的網頁滑動門選單,JS與CSS結合的技術成果,有人說它是自己會切換的網頁選項卡標籤面板,QQ登入後彈出的每日要聞迷你視窗中有類似效果,但是代碼寫法卻是截然不同的,每一位作者的思路是不同的,因此您多了一份參考。

運作效果截圖如下:

線上示範網址如下:

http://demo.jb51.net/js/2015/js-css-auto-cha-tab-menu-style-codes/

具體程式碼如下:

<html>
<head>
<title>自动切换的网页滑动门菜单</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<style type="text/css">
<!--
html, body, ul, ol, li, p, h1, h2, h3, h4, h5, h6, form, fieldset, table, td, img {margin:0; padding:0; border:0;}
td,p,div,li,select,input,textarea {font-size:12px;}
ul {list-style-type:none; text-align:left;}
select,input {vertical-align:middle;}
body { color:#333; repeat-x;}
#wrap { width:750px; margin:0 auto; clear:both; background:#fff;}
.clearit { clear:both;}
a{ color:#039; text-decoration:underline;}
a:hover{ color:#F00; text-decoration:underline;}
.linkN a{ color:#039; text-decoration:none;}
.linkN a:hover{ color:#F00; text-decoration:underline;}
.linkfff a{ color:#fff; text-decoration:none;}
.linkfff a:hover{ color:#F00; text-decoration:underline;}
.linkAD5A00 a { color:#AD5A00; text-decoration:none;}
.linkAD5A00 a:hover { color:#f00; text-decoration:underline;}
.linkC00 a { color:#C00; text-decoration:none;}
.linkC00 a:hover { color:#C00; text-decoration:underline;}
.link666 a { color:#666; text-decoration:none;}
.link666 a:hover { color:#F00; text-decoration:underline;}
h1 { font-size:16px; font-family:simhei; font-weight:500; text-align:center; padding:5px 0 3px 0;}
h2 { font-size:14px; color:#fff; display:block; clear:both; text-align:left;}
h3 { font-size:14px; font-weight:200; no-repeat 2px 7px; border-bottom:2px solid #BBE5F1; padding:5px 0 2px 17px; margin:5px 0;}
span{ font-size:12px; font-weight:200; float:right; margin-right:5px;}
ul { margin:5px 0 0 5px; color:#039;}
li { padding:3px 0 3px 10px; no-repeat 3px 7px;}
.noStyle li { padding:3px 0; background:none;}
ul.two { margin:8px 0 0 12px;}
.two li { padding:3px 0 3px 10px; no-repeat 3px 7px; float:left; width:110px;}
.f14 li { font-size:14px; padding:1px 0 4px 10px;}
.blkT { margin-top:6px;}
.list14 { font-size:14px; line-height:23px;}
/*CSS for 共用模块 end*/
.leW { width:254px;}
.miW { padding:0 5px;}
.riW { width:140px; background:#F3F3F3;}
.riW li { padding:3px 0 3px 6px; no-repeat 0 7px;}
.cont_le { background:#EBF8FB; border:1px solid #A3D8E0; border-top:none; border-bottom:none; padding:8px 0 8px 0;}
.cont_all { background:#EBF8FB; border:1px solid #A3D8E0; border-top:none; padding:8px 0 8px 0;}
.text { padding:4px 0 8px 0; text-align:center;}
.pic { margin:8px 0; text-align:center;}
.textL { text-align:left; padding:3 0 8px 0;}
.blankT { margin-top:8px;}
.picfff { text-align:center;}
.picfff img { border:1px solid #fff; margin:5px 0;}
.partA .jdt { background:#D11C00; padding:5px 0 5px 0; text-align:left;}
.partA .cont_le p { float:left; margin:0 0 0 6px; text-align:center;}
.partA .miW .top { height:17px; no-repeat; text-align:right; padding:5px 18px 0 0; margin-top:8px;}
.partA .miW .top a { color:#C00; text-decoration:underline;}
.partA .miW .top a:hover { color:#C00; text-decoration:none;}
.partA .miW .cont { background:#FFFBEA; border:1px solid #FC6; border-top:none; padding-bottom:5px; border-bottom:none;}
.partA .miW .cont p{ line-height:19px; margin-left:15px;}
.partA .miW .cont .line { repeat-x; height:1px; font-size:0; margin:5px 15px;}
.partA .miW .top1 { height:15px; no-repeat; text-align:left; padding:4px 0 0 23px; margin-left:0; _margin-left:2px;}
.partA .miW .top1 h2 { color:#000;}
.partA .miW .cont1 { border:1px solid #FC6; border-top:none; padding:5px 0 8px 0;}
.partA .shiP { no-repeat bottom; width:120px; height:109px; border:1px solid #A0B2D8; margin:10px 0 0 9px;}
/*标签*/
.menu1Off,.menu1On,.menu2Off,.menu2On,.menu3Off,.menu3On,.menu4Off,.menu4On { height:20px; color:#039; text-align:center; background:#B2DBE1; cursor:pointer; padding-top:3px;}
.menu1On,.menu2On,.menu3On,.menu4On{ color:#C00; background:#fff; border-left:1px solid #34AEBE; border-right:1px solid #34AEBE;}
/*标签a*/
.menua1Off,.menua1On,.menua2Off,.menua2On{ height:16px; width:52px; color:#666; text-align:center; repeat-x; cursor:pointer; padding-top:3px;}
.menua1On,.menua2On{ color:#C00; font-weight:bold; repeat-x; }
.menuCont { background:#F3F3F3;}
.menuCont th { text-align:center; font-weight:200; padding:5px 0 3px 0;}
.menuCont .noBg td { background:#fff; padding:5px 0 3px 5px; border-right:1px solid #F3F3F3; }
.menuCont .noBg1 td { background:#F3F3F3; padding:5px 0 3px 5px; border-right:1px solid #FFF;}
.partA .tuKu { no-repeat; margin-left:5px; height:150px; text-align:center;}
.partA .tuKu p { float:left; margin:0 10px; _margin:0 8px;}
.partA .tuKu img { padding:5px; border:1px solid #D0D1D2; background:#fff; margin:8px 0;}
.partA .shiPyy { border:1px solid #FC6; margin-top:5px;}
.partA .shiPyy h2 { color:#C00; background:#FFEAAF; padding:5px 0 3px 5px;}
.partA .shiPyy img { vertical-align:middle;}
.adv { margin:8px 0;}
.leftW { width:605px; padding-right:5px; text-align:center;}
.leftW .leW { width:140px;}
.leftW .leW img { margin-bottom:8px;}
.leftW .leW p { text-align:left; line-height:19px; padding:0 5px; margin-top:5px;}
.leftW .leW .picText { text-align:left; line-height:19px; padding-right:5px; margin-bottom:8px;}
.leftW .leW .picText img { float:left; margin:0 7px;}
.midW { padding:5px 0 0 5px; text-align:left;}
.midW table { margin-bottom:8px;}
.midW td { line-height:19px; padding:3px 0px;}
.midW span { float:none; color:#929292;}
.midW .more span { float:right;}
.midW .cC00 { color:#C00; font-weight:bold;}
.rightW { width:140px; background:#F3F3F3;}
.rightW p { float:left; margin:5px 0 5px 8px; _margin:5px 0 5px 5px;}
.rightW .cont { text-align:left; line-height:19px; text-align:left; padding:8px 0 0 8px;}
.rightW .date { margin-top:8px;}
.rightW .date td { color:#666; padding:1px 0;}
.rightW .date td { background:#fff; padding:1px 0; color:#039;}
.rightW .date .cF60 { color:#F60; font-weight:bold;}
.rightW .fenX { margin-top:8px; margin-left:3px;}
.rightW .fenX td { padding:5px 0 2px 5px; background:#fff; text-align:left;}
.rightW .blk000 img { border:1px solid #000;}
-->
</style>
</head>
<!--把<body>改为-->
<body onLoad="change_Menu(1)">
<table width="254" cellspacing="0" class="partA">
 <tr>
 <td class="leW" valign="top" width="254">
 <!-- d --> <!-- d -->
 <!-- 舌签排行 begin -->
<script language="JavaScript" type="text/javascript">
//<![CDATA[
var cur_index=1
var num=4 //该值记录标签的个数
var settime
function GetObj(objName){
 if(document.getElementById){
 return eval('document.getElementById("' + objName + '")');
 }else if(document.layers){
 return eval("document.layers['" + objName +"']");
 }else{
 return eval('document.all.' + objName);
 }
}
function change_Menu(index){
 for(var i=1;i<=num;i++){/* 最多支持8个标签 */
 if(GetObj("con"+i)&&GetObj("m"+i)){
 GetObj("con"+i).style.display = 'none';
 GetObj("m"+i).className = "menu"+i+"Off";
 }
 }
 if(GetObj("con"+index)&&GetObj("m"+index)){
 GetObj("con"+index).style.display = 'block';
 GetObj("m"+index).className = "menu"+index+"On";
 }
 cur_index=index
 if(cur_index<num){
 cur_index++
 }
 else{
  cur_index=1
 }
 settime=setTimeout("change_Menu(cur_index)",2000)//设置延迟时间
}
function Menu(c_index){
 clearTimeout(settime)
 change_Menu(c_index)
 } 
//]]>
</script>
<table cellspacing="0" style="background:#3FA6B5; width:100%;" class="clearit">
 <tr>
 <td height="3"></td>
 </tr>
 <tr>
 <td align="center">自动切换</td>
 <td id="m1" onClick="Menu(1)" class="menu1On" title="栏目">栏目1</td>
 <td width="1"></td>
 <td id="m2" onClick="Menu(2)" class="menu2Off" title="栏目">栏目2</td>
 <td width="1"></td>
 <td id="m3" onClick="Menu(3)" class="menu3Off" title="栏目">栏目3</td>
 <td width="1"></td>
 <td id="m4" onClick="Menu(4)" class="menu4Off" title="栏目">栏目4</td>
 <td width="10"></td>
 </tr>
</table>
<div id="con1" class="cont_le picfff">
<p style="margin-left:1px;"><br><a href="#">111</a></p>
<div class="clearit"></div>
</div>
<div id="con2" style="display:none;" class="cont_le picfff">
<p style="margin-left:1px;"><br><a href="#">222</a></p>
<div class="clearit"></div>
</div>
<div id="con3" style="display:none;" class="cont_le picfff">
<p style="margin-left:1px;"><br><a href="#">333</a></p>
<div class="clearit"></div>
</div>
<div id="con4" style="display:none;" class="cont_le picfff">
<p style="margin-left:1px;"><br><a href="#">444</a></p>
<div class="clearit"></div>
</div>
</body>
</html>

希望本文所述對大家的JavaScript程式設計有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn