Skip to content

Instantly share code, notes, and snippets.

@neilgee
Created January 17, 2017 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilgee/a36d3e7772726ee397ec8e1199062154 to your computer and use it in GitHub Desktop.
Save neilgee/a36d3e7772726ee397ec8e1199062154 to your computer and use it in GitHub Desktop.
Scroll Animate JS on Reload
;(function($){
/**
* Store scroll position for and set it after reload
*
* @return {boolean} [loacalStorage is available]
*/
$.fn.scrollPosReload = function(){
if (localStorage) {
var posReader = localStorage["posStorage"];
if (posReader) {
$(window).scrollTop(posReader);
localStorage.removeItem("posStorage");
}
$(this).click(function(e) {
//localStorage["posStorage"] = $(window).scrollTop();
localStorage["posStorage"] = $('html, body').animate({scrollTop});
});
return true;
}
return false;
}
/* ================================================== */
$(document).ready(function() {
// Trigger the reload
$('#edit').scrollPosReload();
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment