Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danieliser/f170acbe9ac23022e5cd657363722246 to your computer and use it in GitHub Desktop.
Save danieliser/f170acbe9ac23022e5cd657363722246 to your computer and use it in GitHub Desktop.
Close a popup if element is scrolled into view, reopen when it goes offscreen.
var was_closed = false;
jQuery(window).on('scroll', function () {
var footer = jQuery('#footer'),
footer_is_visible = footer.offset().top - jQuery(window).scrollTop() < footer.height(),
popup = PUM.getPopup(123),
popup_is_open = popup.hasClass('pum-active');
if (popup_is_open && footer_is_visible) {
PUM.close(123);
was_closed = true;
} elseif (was_closed && !footer_is_visible && !popup_is_open) {
PUM.open(123);
was_closed = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment