简体   繁体   English

实现github.com文件无缝文件导航

[英]Implement github.com file seamless file navigation

I just noticed a recent change when browsing github repositorys. 我刚刚注意到浏览github存储库时最近的一个变化。 When you select a file or folder, the new file slides in and pushed the old file out. 选择文件或文件夹时,新文件将滑入并推出旧文件。 This is easy enough to do with jquery, but what's really different is that the URL itself actually changes so that bookmarks still work. 这很容易与jquery一起使用,但真正不同的是URL本身实际上发生了变化,因此书签仍然有用。 I've been struggling to create this for a book navigating site I'm working on but haven't been able to update the url without a full page refresh. 我一直在努力为我正在处理的图书导航网站创建这个,但是如果没有整页刷新就无法更新网址。 Any ideas on how github does this? 关于github如何做到这一点的任何想法?

It's using the new HTML5 API history.pushState/history.replaceState for doing this (so it only works in modern browsers). 它使用新的HTML5 API history.pushState / history.replaceState来执行此操作(因此它仅适用于现代浏览器)。

See https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries for more details. 有关详细信息,请参阅https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries

If you want a solution for all browsers, then you have to stick to modifying the fragment (the bit after the #) 如果你想要一个适用于所有浏览器的解决方案,那么你必须坚持修改片段(#之后的位)

I haven't looked at the underlying code, but I believe it is a combination of the new HTML5 spec of web history and location (well, location is old, but it's an updated spec). 我没有看过底层代码,但我相信它是Web历史记录和位置的新HTML5规范的组合(好吧,位置很旧,但它是一个更新的规范)。

The W3C specs are very verbose (after all, they are specs), so that can be hard to read. W3C规范非常详细(毕竟,它们是规格),因此很难阅读。 I think this other answer on Stack Overflow is in the right direction. 我认为Stack Overflow的另一个答案是正确的方向。

You have to keep in mind that this is part of the HTML5 specs, so not every browser will be able to handle this functionality. 您必须记住,这是HTML5规范的一部分,因此并非每个浏览器都能够处理此功能。 We are building this type of navigation out on a project at work, and if the browser doesn't support this feature, it's just a regular page refresh. 我们正在工作的项目中构建这种类型的导航,如果浏览器不支持此功能,那么它只是常规页面刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 像Github.com这样的时间表 - Timeline Charts like Github.com 无法解析主机github.com - Could Not Resolve Host github.com pa11y json 动作配置文件:https://github.com/pa11y/pa11y#actions - pa11y json configuration file for actions : https://github.com/pa11y/pa11y#actions 来自https://github.com/RubaXa/Sortable的功能要求 - Function required from https://github.com/RubaXa/Sortable js项目的无缝音频文件连接器? - Seamless audio file concatenator for a js project? 无缝页面加载导航 - Seamless Page Loading Navigation 在异步队列内的函数内进行异步Twitter调用-https://github.com/DeviaVir/zenbot - Async twitter call inside a function that is inside a async queue - https://github.com/DeviaVir/zenbot 无法在meanstack MEANIO上运行localhost:3000,https://github.com/linnovate/mean - cannot run localhost:3000 on meanstack MEANIO, https://github.com/linnovate/mean 如何使用github.com/1000hz/bootstrap-validator的自定义验证器 - How to use custom validators of github.com/1000hz/bootstrap-validator 如何处理“已弃用,请使用https://github.com/pillarjs/path-to-regexp”消息 - how to deal with “DEPRECATED use https://github.com/pillarjs/path-to-regexp” message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM