Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imbdb/f2a833ecc56303879d6fd31e2b23cbfc to your computer and use it in GitHub Desktop.
Save imbdb/f2a833ecc56303879d6fd31e2b23cbfc to your computer and use it in GitHub Desktop.
jQuery : handle events of dynamically generated elements
//SCDGE : Selector of Container containing dynamically generated element
//SDGE : Selector of Dynamically Generated elements
jQuery(<SCDGE>).on('focus',<SDGE>,function () {
var footerHeight = 200; //footerHeight = footer height + element height + buffer
var element = $(this);
if (element.offset().top - ($(window).scrollTop()) > ($(window).height() - footerHeight)) {
$('html, body').animate({
scrollTop: element.offset().top - ($(window).height() - footerHeight)
}, 500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment