源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

页面刷新时记住滚动条的位置jquery代码

  • 时间:2020-09-30 18:49 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:页面刷新时记住滚动条的位置jquery代码
@*点击按钮页面刷新的时候 记住滚动条的位置*@
[u]复制代码[/u] 代码如下:
<script type="text/javascript"> window.onbeforeunload = function () { var scrollPos; if (typeof window.pageYOffset != 'undefined') { scrollPos = window.pageYOffset; } else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { scrollPos = document.documentElement.scrollTop; } else if (typeof document.body != 'undefined') { scrollPos = document.body.scrollTop; } document.cookie = "scrollTop=" + scrollPos; //存储滚动条位置到cookies中 } window.onload = function () { if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) { var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/); //cookies中不为空,则读取滚动条位置 document.documentElement.scrollTop = parseInt(arr[1]); document.body.scrollTop = parseInt(arr[1]); } } </script>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部