Last active
May 22, 2017 11:36
-
-
Save imbdb/f2a833ecc56303879d6fd31e2b23cbfc to your computer and use it in GitHub Desktop.
jQuery : handle events of dynamically generated elements
This file contains hidden or 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
//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