Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18681821
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-17 09:01:42

经过多次改进,可以在普通网站上直接使用了,现在发布源程序下载(编码为utf-8,改为gb3212的是:用记事本打开,另存时选择相应的编码),希望对大家有用(虽然不一定实用)。
欢迎大家继续改进。
功能的实现思路:

S1  

·单击触发
·块锁定:a{display:block;height:16px;}/*将A锁定为块级,再定义高度和宽度*/
·再次单击弹出链接:在
标记的onclick事件中需要执行读取时,return false;否则return true;
·AJAX读取数据
·数据暂存
·窗口平滑收缩


S2   
·鼠标滑过延时触发: onmouseover时var waitInterval=window.setTimeout("func();",300);onmouseout时clearTimeout(waitInterval);
·
块锁定、AJAX读取数据、数据暂存、窗口平滑收缩

其它功能:
·cookie记忆
·最后读取数据的服务器时间

在线效果


源码下载(见附件)

JS文件分析:

CODE:
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 xH=new Object();
var rqtp=new Object();
var dateStr,dStr;
var requestType;
var etype=0;
var newsstring;
var ajccache=new Object();
var url;
var MouseDelayTime=200;//鼠标感应延迟
var waitInterval;
var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);

function SetCookie(name,value,expires){//写cookie
var exp=new Date();
exp.setTime(exp.getTime()+expires*60000);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();//+";domain=arkoo.com;path=/";
}
function readcookie(name){//读取cookie
var oRegex=new RegExp(name+'=([^;]+)','i');
var oMatch=oRegex.exec(document.cookie);
if(oMatch&&oMatch.length>1)return unescape(oMatch[1]);
else return '';
}

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 = "
Loading rquest content fail, Please try it again latter...
";}
       }
   }
}

function getnews(tagid,x){
url = "tab/"+tagid+'_'+x+'.html';
var url2=url;
requestType = tagid;
if(ajccache[url]==null){
var loadstatustext="
Loading request content, please wait...
";
rqtp[tagid]=tagid;
CreateXMLHttpRequest();   
var hdr=tagid;
   xH[tagid]=xmlHttp;
   if(etype==1)getObject(requestType+'_cnt').innerHTML = loadstatustext;
   xH[tagid].onreadystatechange = function(){
   // only if xmlHttp shows "complete"
   if (xH[tagid].readyState == 4){
      // only http 200 to process
      if (window.location.href.indexOf("http")==-1 || xH[tagid].status == 200){
         newsstring = xH[tagid].responseText;
    dateStr=xH[tagid].getResponseHeader("Date");
    dStr = new Date(dateStr);SetCookie('dStr',dStr,10000000);
         //inject centent to tab-pane
            shownews(rqtp[tagid],newsstring);
            ajccache[url2]=newsstring;
      }
   }
}
   xH[tagid].open("GET", url, true);
   xH[tagid].setRequestHeader("If-Modified-Since","0");
   xH[tagid].send(null);
}
else
{shownews(requestType,ajccache[url]);}
}

function shownews(requestType,newsstring){
//    responsecont = getObject(requestType+'_cnt');
    responsecont.innerHTML = newsstring;
    getObject("pdate").innerHTML=dStr;
if(getObject("alta"))ata(getObject("alta"));
//]]>
}


function TabNews(tagid,x){
var mnt=getObject(tagid+"_mn").getElementsByTagName('li').length;
if(!mnt)mnt=7;
    for (var i=1;i<=mnt;i+=2) {
         if (i == x) {
            getObject(tagid+i).className="tabactive"+i;
            if(i!=1){
               getObject(tagid+(i-1)).style.display="none";               
               if(i!=mnt){
                  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!=mnt){
               getObject(tagid+(i+1)).style.display="block";
            }             
        }         
   }
}

var idn,tmpa,tmpat;
var aw="";
var rT;
function aet(objid,tagid,etp){
    var iif=0;
    var lis=objid.getElementsByTagName('li');
    rT=tagid;
    for(var iy=0;iy        if(iif==0){
        iif=1;
        with(lis[iy]){
        if(etp==0){
        lis[iy].onmouseover=function(){
            rT=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
            if(getObject(rT+'_cnt').style.display != "none"&&className!="") return;
            idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
            clearTimeout(waitInterval);
            waitInterval=window.setTimeout("etype=0;TabNews(rT,idn);if(getObject(rT+'_cnt').style.display == 'none')displayList(rT+'_cnt'); SetCookie(rT+'info',idn,10000000);SetCookie(rT+'_cntd','ture',10000000);",MouseDelayTime);
            }
        lis[iy].onmouseout=function(){if(getObject(rT+'_cnt').style.display != "none"&&className!="") return;clearTimeout(waitInterval);}
        }
        if(etp==1){
        lis[iy].onmouseover=function(){getElementsByTagName('a')[0].blur();}
        lis[iy].onclick=function(){
            idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
            rT=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
            if(getObject(rT+'_cnt').style.display != "none"&&(idn==1&&(this.className=="tabactive1")||aw==attributes.getNamedItem('id').value)) return true;
                if(getObject(rT+'_cnt').style.display == "none"){
                displayList(rT+'_cnt');SetCookie(rT+'_cntd','ture',10000000);
                }
            etype=1;
            TabNews(rT,idn);
            SetCookie(rT+'info',idn,10000000);
            aw=attributes.getNamedItem('id').value;
            getElementsByTagName('a')[0].blur();
            return false;
            }}}}
        else{iif=0;}
    }
}

function ata(objid){
var as=objid.getElementsByTagName('a');
for(var i=0;ias[i].target="_self";
}
}


function GetUrlParam(paramName){    //获取URL参数的函数
    var oRegex = new RegExp('[\?&]' + paramName + '=([^&]+)', 'i');
    var oMatch = oRegex.exec(window.location.search);
    if(oMatch && oMatch.length > 1)
        return oMatch[1];
    else
        return '';
}


function hideText(){
if(document.getElementsByTagName("arkoo:title").length==0){
var upu=GetUrlParam("username");
var upa=GetUrlParam("articleid");
getObject("closeit").innerHTML='
查看原文 ×';
}
}

var maxh=new Object();
//显示内容框
function displayList(oid){   
    var h = 0;  
    var objid=getObject(oid);
          if(isNaN(parseInt(maxh[oid]))) var max_h = 210; // 容器的最大高度
        else
            var max_h = maxh[oid];
          var anim = function(){            
                    h += 50; // 每次递增50像素
                    if(h >= max_h){
                    objid.style.height = max_h + "px";;
                    getObject('tab'+objid.attributes.getNamedItem('id').value).style.backgroundImage="url(tab/images/tab_drop1.gif)"; // 让图片标签改变背景          
                    if(tt){window.clearInterval(tt);}
                    }
                    else{
                objid.style.display="block";
                objid.style.height = h + "px";
                    }
            }
               
              var tt = window.setInterval(anim,2);      
}

// 隐藏列表框
function hiddenList(objid){
       var h = objid.offsetHeight;
           var anim = function(){
                 h -= 50; // 每次递减50像素
                 if(h <= 5){
                 objid.style.display="none";
                   getObject('tab'+objid.attributes.getNamedItem('id').value).style.backgroundImage="url(tab/images/tab_drop2.gif)";
                   if(tt){window.clearInterval(tt);}
               }
               else{
                   objid.style.height = h + "px";
               }
           }
             
           var tt = window.setInterval(anim,2);
}

function showClassList(oid){
var objid=getObject(oid);
   if(objid.style.display == "none"){
    if(objid.getElementsByTagName("img").length==0)TabNews(oid.substring(0,oid.indexOf("_")),1);
       displayList(oid); // 显示内容框
    SetCookie(oid+'d',"ture",10000000);
   }
   else{
      if(isNaN(parseInt(maxh[oid]))){
         if(Browser.isFirefox){
            maxh[oid]=objid.offsetHeight;
      }
      else{
         maxh[oid]=objid.offsetHeight; // 内容容器的初始高度
          }
      }
      hiddenList(objid); // 隐藏内容框
    SetCookie(oid+'d',"none",10000000);SetCookie(oid+'h',maxh[oid],10000000);
   }
}

function intiload(){
if(readcookie("tab_cntd")=="none"){
    hiddenList(getObject("tab_cnt"));
    maxh['tab_cnt']    = readcookie("tab_cnth");
getObject("pdate").innerText=readcookie("dStr");
    }
else{
    if(parseInt(readcookie("tabinfo"))>1)
    TabNews("tab",readcookie("tabinfo"));//返回上次访问
    else
    TabNews("tab",1);
    aw="tab"+readcookie("tabinfo");
}
if(readcookie("news_cntd")=="none"){
    hiddenList(getObject("news_cnt"));
    maxh['news_cnt'] = readcookie("news_cnth");
getObject("pdate").innerText=readcookie("dStr");
    }
else{
    if(parseInt(readcookie("newsinfo"))>1)
    TabNews("news",readcookie("newsinfo"));   //返回上次访问
    else
    TabNews("news",1);
}
}
问题:内容容器的初始高度在IE,FF中有不同结果,如何调整?
阅读(332) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~