Skip to content

Instantly share code, notes, and snippets.

@r4fx
Last active September 14, 2015 21:01
Show Gist options
  • Save r4fx/3f0ed09e5930c5ef9e21 to your computer and use it in GitHub Desktop.
Save r4fx/3f0ed09e5930c5ef9e21 to your computer and use it in GitHub Desktop.
Scroll to uploaded file after upload in long form
$(function () {
var locationHashObjTop = false;
$('input[type="submit"]').on('click', function () {
var $locationHashObj = $(this).prev();
var locationHash = '#' + $(this).prev().attr('id');
locationHashObjTop = $locationHashObj.offset().top;
sessionStorage.setItem('fileHash', locationHash);
sessionStorage.setItem('fileHashTop', locationHashObjTop - 150);
});
var fileHash = sessionStorage.getItem('fileHash');
locationHashObjTop = sessionStorage.getItem('fileHashTop');
if (locationHashObjTop) {
$('html,body').scrollTop(locationHashObjTop);
}
$('button[type="submit"]').on('click', function () {
sessionStorage.removeItem('fileHash');
sessionStorage.removeItem('fileHashTop');
});
//console.log(fileHash + ' : ' + locationHashObjTop);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment