Forgot password?
 Register account
View 216|Reply 0

定位到 lastpost

[Copy link]

3158

Threads

7933

Posts

45

Reputation

Show all posts

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

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | 快速注册

$\LaTeX$ formula tutorial

Mobile version

2025-6-8 07:02 GMT+8

Powered by Discuz!

Processed in 0.015555 second(s), 21 queries

× Quick Reply To Top Edit