首页 > 解决方案 > 显示 html 页面的左侧

问题描述

我是 html 和 javacript 的新手,我只知道它们的基础知识。所以我想创建一个基于 html 的网页。

<html>
<body>

uette like a man’s face, a marshy spot beside the river where the waterfowl were easily startled, a tall tree that looked like a man with his arms upraised. 
</body></html>

我想知道当我关闭并重新打开它时,是否有代码可以继续我从该页面离开的位置。我尝试在谷歌上搜索代码,但我找不到任何东西。任何帮助,将不胜感激。谢谢

标签: javascripthtml

解决方案


使用 jQuery 和localStorage

$(document).ready(function() {
  $(window).scroll(function() {
    console.log('scroll')
    let doc = document.documentElement;
    let top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
    console.log('body top', top);
    localStorage.setItem('scroll', top);
  });

  var top = localStorage.getItem('scroll');
  console.log('top', top);
  $('body').scrollTop(top);
});
div {
  height: 5300px; /* for scroll */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
  uette like a man’s face, a marshy spot beside the r iver where the waterfowl were easily startled, a ta ll tree that looked like a man with his arms uprais ed. ............................. ..........................
</div>https://stackoverflow.com/posts/56059324/edit#


推荐阅读