简体   繁体   English

仅在同一页面时记住滚动位置

[英]Remember scroll position only if it is the same page

I am doing a quote website and i have about 300 quotes gruped on about 30 pages ( 10 quotes on the page ).At every quote i have a like button so when i like a quote THIS javascript code remembers the scroll position. 我正在做一个报价网站,大约30页上有300个报价(该页面上有10个报价)。在每个报价上我都有一个喜欢的按钮,所以当我喜欢报价时, javascript代码会记住滚动位置。 But the problem is that when i go to the next page this code remembers the scroll position but i want if the page is different from the previous one ( for example: if the user likes a quote on the page quotes.php?page=3 the javascript code remembers the scroll position of the website when the like button was pressed but if the user go to the bottom of the page and goes on another page by useing the navigation buttons scroll position remains the same like previous )the cookie that was created to be deleted so the page scroll starts from 0 not from 200 for example. 但是问题是,当我转到下一页时,此代码会记住滚动位置,但是我希望页面是否与上一页不同(例如:如果用户喜欢页面上的报价quotes.php?page = 3 javascript代码会在按下“赞”按钮时记住网站的滚动位置,但是如果用户转到页面底部并通过使用导航按钮转到另一个页面,则滚动位置仍与上一个相同)。被删除,因此页面滚动从0开始而不是从200开始。

This is an idea on how my website looks like on top at 0 scroll. 是关于我的网站在0滚动顶部的外观的想法。
This is an idea on how my website looks like on bottom at max scroll 是关于我的网站在最大滚动底部时的外观的想法

Scroll position script is used in body 正文中使用了滚动位置脚本

<body onunload="unloadP('UniquePageNameHereScroll')" onload="loadP('UniquePageNameHereScroll')">

That script defined the parameter "page name". 该脚本定义了参数“页面名称”。 Maybe you can try to assign different name per page. 也许您可以尝试为每页分配不同的名称。

<body onunload="unloadP('UniquePageNameHereScroll')" onload="loadP('UniquePageNameHereScroll')">

Eg. 例如。

<body onunload="unloadP('page1')" onload="loadP('page1')">
...
<body onunload="unloadP('page2')" onload="loadP('page2')">

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM