Created
January 17, 2017 23:55
-
-
Save neilgee/a36d3e7772726ee397ec8e1199062154 to your computer and use it in GitHub Desktop.
Scroll Animate JS on Reload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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