I'm using jquery and cookie.jquery to remember the scroll position. Is there anything I can do to improve my code? Thanks!
$(document).ready(function() {
// convert cokkie variable for easy access
var prev_scroll_position = $.cookie('prev_scroll_position');
// scroll to position
$(window).scrollTop(prev_scroll_position);
// update cookie when user scrolls
$(window).scroll(function (event) {
var scroll_positon = $(window).scrollTop();
$.cookie('prev_scroll_position', scroll_positon, { expires: 7, path: '/' });
});
});
debounce
function, so the scroll function wont be called for every pixel, but after scrolling has stopped for Xms - davidwalsh.name/javascript-debounce-function. This will prevent the scroll-function to be a bottleneck while scrolling – TryingToImprove Feb 2 at 13:19