【问题标题】:How to store the item currently scrolled to in the URL?如何将当前滚动到的项目存储在 URL 中?
【发布时间】:2021-11-08 22:27:43
【问题描述】:

所以我有一个显示 100 项列表的页面。如何将滚动到的项目存储在 URL 中,以便用户可以控制滚动到 URL 中的项目?

www.site.com/inventory?scroll_position=67

【问题讨论】:

  • 不知道你是什么意思 store...... store 在哪里?
  • 你的意思是使用#link吗?
  • www.site.com/inventory#item-67 讨论了如何在屏幕中心找到项目stackoverflow.com/q/11760898/15273968
  • edit你的问题表明你做了什么研究和你所做的任何尝试。

标签: javascript html css


【解决方案1】:

在您希望滚动到的文本处添加一个标签:

<a name="scroll_position=67"></a>

url需要读取:www.myawesomesite.com/inventory#67

当页面加载时运行以下javascript:

function scrollTo(hash)
{
 location.hash='#'+hash;
}

【讨论】:

    猜你喜欢
    • 2019-02-24
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 2012-06-02
    • 2014-12-24
    相关资源
    最近更新 更多