DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> Ajax標簽導航效果
Ajax標簽導航效果
編輯:AJAX詳解     

function.JS

 

<!--
function getObject(objectId) {
     if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
       return document.getElementById(objectId);
     }
     else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
       return document.all(objectId);
     }
     else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
       return document.layers[objectId];
     }
     else {
       return false;
    }
}

var responsecont;
var XMLHttp;
var requestType;
var newsstring;

function CreateXMLHttpRequest(){
   // Initialize Mozilla XMLHttpRequest object
   if (window.XMLHttpRequest){
       xmlHttp = new XMLHttpRequest();
   }
   // Initialize for IE/Windows ActiveX version
   else if (window.ActiveXObject) {
       try{
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
       }
       catch (e){
            try{
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){newsstring = "服務器繁忙,請稍後重新連接!";}
       }
   }
}

function getnews(tagid,x){
   var url = tagid+'_'+x+'.htm';
   requestType = tagid;
   CreateXMLHttpRequest();  
  
   XMLHttp.onreadystatechange = processRequestChange;
   XMLHttp.open("GET", url, true);
   XMLHttp.setRequestHeader("If-ModifIEd-Since","0");
   XMLHttp.send(null); 
}

function processRequestChange(){
   // only if XMLHttp shows "complete"
   if (XMLHttp.readyState == 4){
      // only http 200 to process
      if (window.location.href.indexOf("http")==-1 || XMLHttp.status == 200){         
   newsstring = XMLHttp.responseText;
         //inject centent to tab-pane
            shownews(requestType,newsstring);
      }
   }
}

function shownews(requestType,newsstring){
//<![CDATA[
    responsecont = getObject(requestType+'_cnt');
    responsecont.innerHtml = newsstring;
//]]>
}

function TabNews(tagid,x){
    for (var i=1;i<=7;i+=2) {
         if (i == x) {
            getObject(tagid+i).className="tabactive"+i;
            if(i!=1){
               getObject(tagid+(i-1)).style.display="none";              
               if(i!=7){
                  getObject(tagid+(i+1)).style.display="none";
               }                
            }
            if(i==1){
               getObject(tagid+"2").style.display="none";
            }
            try{           
               getnews(tagid,i);
            }
            catch(e){
               alert(e);
            } 
        }
        else
        {
            getObject(tagid+i).className="";           
            if(i!=7){
               getObject(tagid+(i+1)).style.display="block";
            }            
        }        
   }
}
//-->

style.CSS

 

body{ margin: 0;padding: 0;background: #FFF;color: #000;font: normal 12px 宋體,arial,sans-serif;text-align: left;}
div,form,ul,ol,li,span,p {border: 0;margin: 0;padding: 0;}

/*鏈接樣式*/
a:link{color: #000;text-decoration: none;}
a:visited{color: #000;text-decoration: none;}
a:hover{color: #16387C;text-decoration: underline;}

/*清除float*/
.clear{ clear: both; font-size:1px; visibility: hidden; }

/*空格*/
.blank2{font-size: 1px;height: 2px;margin: 0 auto;width: 962px;}
.blank5{font-size: 1px;height: 5px;margin: 0 auto;width: 950px;}
.sblank2{font-size: 1px;height: 2px;margin: 0 auto;width: 100px;}
.sblank3{font-size: 1px;height: 3px;margin: 0 auto;width: 100px;}
.sblank5{font-size: 1px;height: 5px;margin: 0 auto;width: 400px;}
.sblank7{font-size: 1px;height: 7px;margin: 0 auto;width: 400px;}

/*邊距*/
.margin-right{margin-right: 6px;}
.margin-right-left{margin-right: 3px; margin-left:3px;}

/*字體顏色*/
.fcborange{color: #F0741A;font: bold 12px arial,sans-serif;}
.fcred{color:#FF0000;}
.fcwhite{color:#FFF;font:normal 13px 宋體,arial,sans-serif;letter-spacing:1px;}

/*新聞標簽導航*/
.news_tabsnav{
    background: url(../images/tab_bg.gif) #FFF left top repeat-x;
    border: solid #B0BEC7;
    border-width: 0 1px 0 1px;
    height: 22px;
    margin: 0 auto;
    padding: 0;
    width: 506px;
}

.news_tabsnav .tabsmenu{
    height: 22px;
}

.news_tabsnav .tab_sline {
    padding-top: 3px;
    width: 2px;
}

.news_tabsnav li {
    color: #18397C;
    display: inline;
    float: left;
    font: normal 12px 宋體,arial,sans-serif;
    letter-spacing: 1px;
    list-style-type: none;
    margin: 0;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

/*導航菜單點擊後的樣式*/
.news_tabsnav .tabactive1{
    background: url(../images/tab_active1.gif);
    color: #F26400;
    font: bold 12px 宋體,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

.news_tabsnav .tabactive3{
    background: url(../images/tab_active2.gif);
    color: #F26400;
    font: bold 12px 宋體,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

.news_tabsnav .tabactive5{
    background: url(../images/tab_active2.gif);
    color: #F26400;
    font: bold 12px 宋體,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

.news_tabsnav .tabactive7{
    background: url(../images/tab_active2.gif);
    color: #F26400;
    font: bold 12px 宋體,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

/*最新消息主體*/
.news_content{
    border: solid #B0BEC7;
    border-width: 0 1px 1px 1px;
    margin: 0 auto;
    width: 506px;
}

/*推薦新聞列表*/
.news_list{
    height: 120px;
    margin: 0 auto;
    width: 492px;
}

.news_list img{
    border: 1px solid #9EB1C0;
    float: left;
    height: 115px;
    margin: 0;
    padding: 1px;
    width: 154px;
    cursor: pointer;
}

.news_list .new_top7{
    float: right;
    height: 120px;
    margin: 0;
    width: 325px;
}

.news_list .new_top7 li{
    float: left;
    font: normal 13px 宋體,sans-serif;
    height: 12px;
    letter-spacing: 1px;
    list-style-type: none;
    margin: 0;
    padding: 0 0 5px 0!important;
    padding: 0 0 2px 0;
    width: 322px;
}

.news_list .new_top7 li a:link,a:visited{
    color: #18397C;
}

.news_list .new_top7 li a:hover{
    color: #FF0000;
}

/*LOGO廣告*/
.logos{
    margin: 0 auto;
    width: 488px;
    height: 44px;
    padding: 1px !important;
    border: 1px solid #9EB1C0;
}

.logoscnt{
    margin: 0 auto;
    width: 488px;
    height: 31px !important;
    height: 29px;
    padding: 6px 0 7px 0 !important;
    padding: 4px 0 5px 0;
    text-align: center;
    background: url(../images/logos_bg.gif);
}

/*基本信息統計*/
.siteinfo{
    height: 12px;
    letter-spacing: 1px;
    margin: 0 auto;
    padding: 4px 0 4px 0 !important;
    padding: 2px 0 2px 0;
    text-align: center;
    width: 490px;
}

CODE:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xHtml1-transitional.dtd">
<html XMLns="http://www.w3.org/1999/xHtml">
<head>
<meta http-equiv="Content-Type" content="text/Html; charset=utf-8" />
<title>標簽導航</title>
<meta name="Author" content="Robert" />
<link href="css/style.css" rel="stylesheet" type="text/CSS" />
<script language="Javascript" type="text/Javascript" src="js/function.JS"></script>
</head>
<body>
<div class="sblank2"></div>
<div class="news_tabsnav">
               <ul class="tabsmenu">
                  <li class="tabactive1" style="cursor:pointer" id="tab1" >推薦信息</li>
                  <li class="tab_sline" style="display:none" id="tab2"><img src="http://www.pushad.com/Info/images/tab_sline.gif" alt="分割線" /></li>
                  <li style="cursor:pointer" id="tab3" >最新折扣信息</li>
                  <li class="tab_sline" id="tab4"><img src="http://www.pushad.com/Info/images/tab_sline.gif" alt="分割線" /></li>
                  <li style="cursor:pointer" id="tab5" >最新團夠信息</li>
                  <li class="tab_sline" id="tab6"><img src="http://www.pushad.com/Info/images/tab_sline.gif" alt="分割線" /></li>
                  <li style="cursor:pointer" id="tab7" >最新活動信息</li>
               </ul><div class="clear"></div>     
</div>
<div class="news_content">
                  <div id="tab_cnt">
               <div class="sblank2"></div>
               <div class="news_list">
                    <img src="http://www.pushad.com/Info/images/gyy.jpg" alt="推薦圖片新聞" width="154" height="115" border="0" />
                    <ul class="new_top7">
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                    </ul>
                    <div class="clear"></div>
               </div>
               <div class="sblank2"></div>
               <div class="logos">
                    <div class="logoscnt">
                         <img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" />                   
                    </div>
               </div>
               </div>
               <div class="siteinfo">
                  VIP會員共計<span class="fcborange">10200</span>家,今日注冊<span class="fcborange">68</span>人,更新<span class="fcborange">5365</span>條信息,當前總在線<span class="fcborange">62400</span>人
               </div>
</div>
<div class="sblank2"></div>
<div class="news_tabsnav">
               <ul class="tabsmenu">
                  <li class="tabactive1" style="cursor:pointer" id="news1" >華夏資訊推薦</li>
                  <li class="tab_sline" style="display:none" id="news2"><img src="http://www.pushad.com/Info/images/tab_sline.gif" alt="分割線" /></li>
                  <li style="cursor:pointer" id="news3" >華夏動感寶貝</li>
                  <li class="tab_sline" id="news4"><img src="http://www.pushad.com/Info/images/tab_sline.gif" alt="分割線" /></li>
                  <li style="cursor:pointer" id="news5" >華夏動漫世界</li>
                  <li class="tab_sline" id="news6"><img src="http://www.pushad.com/Info/images/tab_sline.gif" alt="分割線" /></li>
                  <li style="cursor:pointer" id="news7" >華夏體育世界</li>
               </ul><div class="clear"></div>     
</div>
<div class="news_content">
                  <div id="news_cnt">
               <div class="sblank2"></div>
               <div class="news_list">
                    <a href="#"><img src="http://www.pushad.com/Info/images/pic.jpg" alt="推薦圖片新聞" width="154" height="115" border="0" /></a>
                    <ul class="new_top7">
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖襯衣最後的搶購機搶購機</a> 2006-08-15</li>
                    </ul>
                    <div class="clear"></div>
               </div>
               <div class="sblank2"></div>
               <div class="logos">
                    <div class="logoscnt">
                         <img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" /><img src="http://www.pushad.com/Info/images/clogo.gif" class="margin-right-left" alt="logo" />                   
                    </div>
               </div>
               </div>
               <div class="siteinfo">
                  VIP會員共計<span class="fcborange">10200</span>家,今日注冊<span class="fcborange">68</span>人,更新<span class="fcborange">5365</span>條信息,當前總在線<span class="fcborange">62400</span>人
               </div>
</div>
</body>
</Html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved