Joo*_*nas 16
我意识到我错过了提交的重要部分,因此,我决定调整代码以在点击事件上存储cookie,而不是在滚动时存储它的原始方式.
这是一种jquery方式:
jsfiddle (/show如果要在框架外查看它,只需添加到网址的末尾)
非常重要的是,你需要jquery cookie插件.
jQuery的:
// When document is ready...
$(document).ready(function() {
// If cookie is set, scroll to the position saved in the cookie.
if ( $.cookie("scroll") !== null ) {
$(document).scrollTop( $.cookie("scroll") );
}
// When a button is clicked...
$('#submit').on("click", function() {
// Set a cookie that holds the scroll position.
$.cookie("scroll", $(document).scrollTop() );
});
});
Run Code Online (Sandbox Code Playgroud)
这里仍然是原始答案的代码:
jQuery的:
// When document is ready...
$(document).ready(function() {
// If cookie is set, scroll to the position saved in the cookie.
if ( $.cookie("scroll") !== null ) {
$(document).scrollTop( $.cookie("scroll") );
}
// When scrolling happens....
$(window).on("scroll", function() {
// Set a cookie that holds the scroll position.
$.cookie("scroll", $(document).scrollTop() );
});
});
Run Code Online (Sandbox Code Playgroud)
@Cody的回答让我想起了重要的事情.
我只是检查并垂直滚动到位置.
| 归档时间: |
|
| 查看次数: |
25128 次 |
| 最近记录: |