久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Facebook 如何在加載不同頁面時保持頁眉和頁腳固

How does Facebook keep the header and footer fixed while loading a different page?(Facebook 如何在加載不同頁面時保持頁眉和頁腳固定?)
本文介紹了Facebook 如何在加載不同頁面時保持頁眉和頁腳固定?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

瀏覽 Facebook 頁面時,頁眉和固定頁腳部分在頁面加載之間保持可見,并且地址欄中的 URL 會相應更改.至少,這是我得到的錯覺.

When browsing through Facebook pages the header and fixed footer section remain visible between page loads AND the URL in the address bar changes accordingly. At least, that's the illusion I get.

從技術上講,Facebook 如何做到這一點?

How does Facebook achieve that technically speaking?

推薦答案

請參閱 Mark Brittingham 的答案以了解如何設置它的樣式,盡管我認為這不是您在這里要問的.我將為您提供有關它如何工作的技術細節(以及為什么它相當出色).

Refer to Mark Brittingham's answer for how to style it, although I don't think that is what you are asking here. I will give you the technical details on how it works (and why it is fairly brilliant).

當您將鼠標懸停在標題中的個人資料鏈接上時,請查看狀態欄...

Take a look at the status bar when you hover over the Profile link in the header...

http://www.facebook.com/profile.php?id=514287820&ref=profile

這就是<a>標簽被指向.現在點擊地址欄看看...

That is where that <a> tag is pointed to. Now look at the address bar when you click it...

http://www.facebook.com/home.php#/profile.php?id=514287820&ref=profile

注意#"片段標識符/哈希?這基本上證明你沒有離開頁面,并且之前的請求是用 AJAX 發出的.他們正在攔截這些鏈接上的點擊事件,并用他們自己的東西覆蓋默認功能.

Notice the "#" fragment identifier/hash? This basically proves that you haven't left the page and the previous request was made with AJAX. They are intercepting the click events on these links, and overriding the default functionality with something of their own.

要使用 Javascript 實現這一點,您所要做的就是為這些鏈接分配一個點擊事件處理程序......

To make this happen with Javascript, all you have to do is assign a click event handler to those links like so...

var header = document.getElementById('header');
var headerLinks = header.getElementsByTagName('a');

for(var i = 0, l = headerLinks.length; i < l; i++) {
  headerLinks[i].onclick = function() {
    var href = this.href;

    //Load the AJAX page (this is a whole other topic)
    loadPage(href);  

    //Update the address bar to make it look like you were redirected
    location.hash = '#' + href;

    //Unfocus the link to make it look like you were redirected
    this.blur();

    //Prevent the natural HTTP redirect
    return false;
  }
}

這種方法的一個絕妙的好處是它允許后退按鈕發揮作用(添加了一些技巧),這在傳統上一直是長期使用 AJAX 的痛苦副作用.我不能 100% 確定這個詭計是什么,但我敢打賭,它能夠以某種方式檢測瀏覽器何時修改片段標識符(可能每 500 毫秒檢查一次).

One fabulous benefit to this approach is that it allows the back button to be functional (with a little added trickery), which has traditionally been a painful side effect of chronic AJAX usage. I'm not 100% sure of what this trickery is, but I bet it's somehow able to detect when the browser modifies the fragment identifier (possibly by checking it every ~500 milliseconds).

附帶說明,將哈希更改為在 DOM 中找不到的值(通過元素 ID)會將頁面一直滾動到頂部.看看我在說什么:從 Facebook 頂部向下滾動大約 10 個像素,露出頂部菜單的一半.單擊其中一個項目,它會在片段標識符更新后立即將其跳回到頁面頂部(沒有任何窗口重繪/重繪延遲).

As a side note, changing the hash to a value that can't be found within the DOM (via element ID) will scroll the page all the way to the top. To see what I'm talking about: you scroll down about 10 pixels from the top of Facebook, exposing half of the top menu. Click on one of the items, it will jump it back up to the top of the page as soon as the fragment identifier gets updated (without any window repaint/redraw delay).

這篇關于Facebook 如何在加載不同頁面時保持頁眉和頁腳固定?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 国产精品爱久久久久久久 | av片免费| 中文字幕一区二区三区四区五区 | 99精品一级欧美片免费播放 | 中文字幕视频在线观看 | а_天堂中文最新版地址 | 久久机热 | 一区二区三区欧美在线 | 欧美极品少妇xxxxⅹ免费视频 | 毛片链接 | 97成人在线 | www.色午夜.com | 久久88 | 国产一区二区三区在线免费观看 | www一级片 | 天天操伊人 | 日韩午夜在线播放 | 黑人巨大精品欧美一区二区免费 | 成人免费视频 | 在线2区 | 成人黄色a | 欧美国产日本一区 | 99精品视频免费观看 | 色婷婷精品国产一区二区三区 | 国产高清在线观看 | 女生羞羞视频 | 日韩亚洲一区二区 | 婷婷激情在线 | 一区二区三区免费 | 99一区二区 | 亚洲综合一区二区三区 | 日韩中文字幕在线观看 | 婷婷综合久久 | 日p视频免费看 | 国产视频91在线 | 久久久久国产一级毛片高清网站 | 国产精品久久久久久久久免费樱桃 | 久久精品国产99国产精品 | 91新视频 | 国产91精品久久久久久久网曝门 | 成年人视频在线免费观看 |