|
kuing 发表于 2021-12-26 20:40
先前就发觉,在头像那块不显示的情况下,是无法定位到 lastpost 的。
例如在手机上,在论坛主页点击最新的帖子,这时正常来说是会定位到最后的回帖处,而实际并没有。
当时没太在意,今晚再分析网页源码才知道,原来 #lastpost 正是藏在头像那块的开头,故此当那块不显示,浏览器就找不到它的位置了。
弄懂之后要解决它也不难了,只要想办法把它弄出来,现已解决。 例如这帖
(例如从index点击标题或forumdisplay页点击最后发表日期进入) 虽然location.hash 是#lastpost 看到的却是页尾, 每次需要向上滚动
建议MathJax排版后重新定位#lastpost
- document.getElementsByName('lastpost')[0].scrollIntoView()
Copy the Code 一般地, 只要有URI fragment就需要重新定位, 大概可以这样:
- if(location.hash){document.getElementsByName(location.hash.slice(1))[0].scrollIntoView()}
Copy the Code 其中location.hash.slice(1) 是把#号去掉.
最后仿照这段代码大概可以写成这样(未测试过):
- MathJax.startup.promise = MathJax.startup.promise.then(()=>if(location.hash){document.getElementsByName(location.hash.slice(1))[0].scrollIntoView()})
Copy the Code |
|