javascript - 显示 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>
我想知道当我关闭并重新打开它时,是否有代码可以继续我从该页面离开的位置。我尝试在谷歌上搜索代码,但我找不到任何东西。任何帮助,将不胜感激。谢谢
解决方案
使用 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#
推荐阅读
- apache-poi - 如何修复“提供的数据似乎在 Office 2007+ XML 中。”
- c++ - 如何设置 VSCode 调试器以使用 cmake?
- c++ - 在模板类中使用友元运算符重载函数,错误未定义引用
- virtual-machine - 比实时运行更快的虚拟机
- css - css-grid sass -> css 不正常
- java - 如何不创建许多仅用于序列化嵌套 JSON 有效负载的类?
- c# - 如何在运行时将 TIFF 转换为 png/jpg 并在 Asp.Net Core 中显示?
- swift - 如何播放序列 MP3 文件?
- db2 - varchar 的长度对性能有影响吗
- javascript - Injecting jQuery using bookmarklet not working on a page