Implementation of Yahoo! and NetEase ajax tag navigation

Source: Internet
Author: User
After many improvements, you can directly apply the code on a common website. now we announce the download of the source program (encoded as UTF-8 and changed to gb3212 by using Notepad, select the corresponding encoding when saving the file) and hope it will be useful to you (though not necessarily practical)

After many improvements, you can directly apply the code on a common website. now we announce the download of the source program (encoded as UTF-8 and changed to gb3212 by using Notepad, select the corresponding encoding when saving the file), hope it is useful to everyone (although not necessarily practical ).
Because it is only a tag navigation, all content will be displayed on the channel page, and all content will be read using AJAX.

Benefits:

Yahoo China

  • Click trigger
  • Block lock: a {display: block; height: 16px;}/* lock A to block level, and then define the height and width */
  • Click the pop-up link again: return false when read is required in the marked onclick event; otherwise, return true;
  • AJAX data reading
  • Temporary data storage
  • Smooth window compression

NetEase

  • Trigger when the mouse slides over the delay: var waitInterval = window. setTimeout ('func (); ', 300); clearTimeout (waitInterval) when onmouseout );
  • Block locking, AJAX data reading, temporary data storage, and smooth window compression

Other functions:

  • Cookie memory
  • Last server time for data reading
  • Sliding door tips

Online consequences:
Http://www.lorlo.com/tab.html

Download source code:Click here to download the source file

JS file analysis:

Code copy box
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; // mouse-induced delay 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) {// write cookievar exp = new Date (); exp. setTime (exp. getTime () expires * 60000); document. cookie = name' = 'escape (value) '; expires = 'Exp. toGMTString (); // '; domain = arkoo.com; path =/';} function readcookie (name) {// read cookievar oRegex = new RegExp (name' = ([^;]) ',' I '); var omatchpolicoregex.exe c (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, Pl 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) {// <! [CDATA [responsecont = getObject (requestType '_ cnt'); responsecont. innerHTML = newsstring; getObject ('pdate '). innerHTML = dStr; if (getObject ('Alta ') {ata (getObject ('Alta'); hideText () ;}//] >} function TabNews (tagid, x) {var lim = getObject (tagid '_ mn '). getElementsByTagName ('Lil'); var mnt = getObject (tagid '_ mn '). getElementsByTagName ('Lil '). length; if (! Mnt) mnt = 4; for (var I = 0; I 1) TabNews (tagid, readcookie (wnf); // return the last visited else TabNews (tagid, 1); if (etp = 1) aw = tagid readcookie (wnf);} for (var iy = 0; iy = Max_h) {objid. style. height = max_h 'px '; getObject ('Tab' objid. attributes. getNamedItem ('id '). value ). style. background = 'URL (tab/images/tab_bgs.gif) 5px-113px no-repeat '; // make the image tag transform background if (tt) {window. clearInterval (tt) ;}} else {objid. style. display = 'block'; objid. style. height = h 'px ';} var tt = window. setInterval (anim, 2);} // hide the function hiddenList (objid) {var h = objid. offsetHeight; var anim = function () {h-= 50; // Each decrease by 50 pixels if (h <= 5) {objid. style. display = 'none'; getObject ('Tab 'objid. attributes. getNamedItem ('id '). value ). style. background = 'URL (tab/images/tab_bgs.gif)-14px-114px no-repeat '; 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) in the displayed content box );} else {if (isNaN (parseInt (maxh [oid]) {if (Browser. isFirefox) {maxh [oid] = objid. offsetHeight;} else {maxh [oid] = objid. offsetHeight; // the initial height of the content container} hiddenList (objid); // The SetCookie (oid 'D', 'none', 10000000) in the hidden content box ); setCookie (oid 'H', maxh [oid], 10000000 );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.