Ajax標(biāo)簽導(dǎo)航效果(仿網(wǎng)易首頁(yè))
更新時(shí)間:2006年10月26日 00:00:00 作者:
根據(jù)yaohaixiao的Ajax標(biāo)簽導(dǎo)航效果:http://www.blueidea.com/tech/web/2006/4144.asp改進(jìn)。
效果:
http://www.lorlo.com/tab.html
主要是改了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;
var ajccache=new Object();//緩存已訪問的數(shù)據(jù)頁(yè)面
var url;
var MouseDelayTime=150;//鼠標(biāo)感應(yīng)延遲
var waitInterval;
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 = "<div class='loading'>Loading rquest content fail, Please try it again latter...</div>";}
}
}
}
function getnews(tagid,x){
url = "tab/"+tagid+'_'+x+'.html';
// var loadstatustext="<div class='loading'><img src='images/loading.gif' /> Loading request content, please wait...</div>";
requestType = tagid;
if(ajccache[url]==null){
CreateXMLHttpRequest();
// getObject(requestType+'_cnt').innerHTML = loadstatustext;
xmlHttp.onreadystatechange = processRequestChange;
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.send(null);
}
else
{ shownews(requestType,ajccache[url]); }
}
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);
ajccache[url]=newsstring; //把已訪問的數(shù)據(jù)緩存下來
}
}
}
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";
}
}
}
}
var idn;
function aet(objid,tagid,etp){ //為L(zhǎng)I加上事件 objid:容器ID tagid:組別 etp:觸發(fā)類型 0-onmouseover 1-onclick
var iif=0;
var lis=objid.getElementsByTagName('li');
requestType=tagid;
url = "tab/"+requestType+"_1.html";
ajccache[url]=getObject(requestType+'_cnt').innerHTML;
for(var iy=0;iy<lis.length;iy++){
if(iif==0){
iif=1;
with(lis[iy]){
if(etp==0){
lis[iy].onmouseover=function(){
if(this.status=="active") return;
requestType=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
clearTimeout(waitInterval);
waitInterval=window.setTimeout("TabNews(requestType,idn);",MouseDelayTime);
}
lis[iy].onmouseout=function(){if(this.status=="active") return;clearTimeout(waitInterval);}
}
if(etp==1){
lis[iy].onmouseover=function(){}
lis[iy].onclick=function(){
if(this.status=="active") return;
requestType=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
var loadstatustext="<div class='loading'><img src='images/loading.gif' /> Loading request content, please wait...</div>";
getObject(requestType+'_cnt').innerHTML = loadstatustext;
TabNews(requestType,idn);
}}}}
else{iif=0;}
}
}
function ata(objid){ //一個(gè)無關(guān)的函數(shù),為解決一個(gè)鏈接問題
var as=objid.getElementsByTagName('a');
for(var i=0;i<as.length;i++){
as[i].pathname="/showfile.html";
}
}
//-->
效果:
http://www.lorlo.com/tab.html
主要是改了JS:
復(fù)制代碼 代碼如下:
<!--
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;
var ajccache=new Object();//緩存已訪問的數(shù)據(jù)頁(yè)面
var url;
var MouseDelayTime=150;//鼠標(biāo)感應(yīng)延遲
var waitInterval;
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 = "<div class='loading'>Loading rquest content fail, Please try it again latter...</div>";}
}
}
}
function getnews(tagid,x){
url = "tab/"+tagid+'_'+x+'.html';
// var loadstatustext="<div class='loading'><img src='images/loading.gif' /> Loading request content, please wait...</div>";
requestType = tagid;
if(ajccache[url]==null){
CreateXMLHttpRequest();
// getObject(requestType+'_cnt').innerHTML = loadstatustext;
xmlHttp.onreadystatechange = processRequestChange;
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.send(null);
}
else
{ shownews(requestType,ajccache[url]); }
}
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);
ajccache[url]=newsstring; //把已訪問的數(shù)據(jù)緩存下來
}
}
}
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";
}
}
}
}
var idn;
function aet(objid,tagid,etp){ //為L(zhǎng)I加上事件 objid:容器ID tagid:組別 etp:觸發(fā)類型 0-onmouseover 1-onclick
var iif=0;
var lis=objid.getElementsByTagName('li');
requestType=tagid;
url = "tab/"+requestType+"_1.html";
ajccache[url]=getObject(requestType+'_cnt').innerHTML;
for(var iy=0;iy<lis.length;iy++){
if(iif==0){
iif=1;
with(lis[iy]){
if(etp==0){
lis[iy].onmouseover=function(){
if(this.status=="active") return;
requestType=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
clearTimeout(waitInterval);
waitInterval=window.setTimeout("TabNews(requestType,idn);",MouseDelayTime);
}
lis[iy].onmouseout=function(){if(this.status=="active") return;clearTimeout(waitInterval);}
}
if(etp==1){
lis[iy].onmouseover=function(){}
lis[iy].onclick=function(){
if(this.status=="active") return;
requestType=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
var loadstatustext="<div class='loading'><img src='images/loading.gif' /> Loading request content, please wait...</div>";
getObject(requestType+'_cnt').innerHTML = loadstatustext;
TabNews(requestType,idn);
}}}}
else{iif=0;}
}
}
function ata(objid){ //一個(gè)無關(guān)的函數(shù),為解決一個(gè)鏈接問題
var as=objid.getElementsByTagName('a');
for(var i=0;i<as.length;i++){
as[i].pathname="/showfile.html";
}
}
//-->
相關(guān)文章
簡(jiǎn)述Ajax的優(yōu)點(diǎn)與缺點(diǎn)
這篇文章主要介紹了Ajax的優(yōu)點(diǎn)與缺點(diǎn)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11解析ajax核心XMLHTTPRequest對(duì)象的創(chuàng)建與瀏覽器的兼容問題
這篇文章主要介紹了ajax核心XMLHTTPRequest對(duì)象的創(chuàng)建與瀏覽器的兼容問題。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12JQuery ajax返回JSON時(shí)的處理方式 (三種方式)
json數(shù)據(jù)是一種經(jīng)型的實(shí)時(shí)數(shù)據(jù)交互的數(shù)據(jù)存儲(chǔ)方法,使用到最多的應(yīng)該是ajax與json配合使用了,下面由腳本之家小編給大家分享JQuery ajax返回JSON時(shí)的處理方式 (三種方式),需要的朋友可以參考下2015-09-09用Promise解決多個(gè)異步Ajax請(qǐng)求導(dǎo)致的代碼嵌套問題(完美解決方案)
這篇文章主要介紹了用Promise解決多個(gè)異步Ajax請(qǐng)求導(dǎo)致的代碼嵌套問題(完美解決方案),需要的朋友可以參考下2017-02-02Ajax bootstrap美化網(wǎng)頁(yè)并實(shí)現(xiàn)頁(yè)面的加載刪除與查看詳情
Bootstrap是Twitter推出的一個(gè)開源的用于前端開發(fā)的工具包,Bootstrap提供了優(yōu)雅的HTML和CSS規(guī)范,它即是由動(dòng)態(tài)CSS語言Less寫成。下面通過本文給大家介紹Ajax bootstrap美化網(wǎng)頁(yè)并實(shí)現(xiàn)頁(yè)面的加載刪除與查看詳情,需要的朋友可以參考下2017-03-03添加后臺(tái)list給前臺(tái)select標(biāo)簽賦值簡(jiǎn)單實(shí)現(xiàn)
本文為大家介紹下通過添加后臺(tái)list怎么實(shí)現(xiàn)給前臺(tái)select標(biāo)簽賦值,具體代碼如下,感興趣的朋友可以參考下哈2013-07-07