Skip to content

Instantly share code, notes, and snippets.

@gindis
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save gindis/10956435 to your computer and use it in GitHub Desktop.

Select an option

Save gindis/10956435 to your computer and use it in GitHub Desktop.
记录上一次浏览页面位置
!function (){
'use strict';
if (localStorage) {
var docEle,
w = window,
d = document,
l = localStorage,
t = location.href,
browserName=navigator.userAgent.toLowerCase();
//兼容IE
if ((/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))||(/webkit/i.test(browserName))) {
docEle = d.body
}else {
docEle = d.documentElement ? d.documentElement : d.body;
}
//初始上一次浏览位置
docEle.scrollTop = l.getItem(t);
w.onscroll = function () {
//记录当前位置
l.setItem(t, docEle.scrollTop);
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment