Quick: When #element reaches the top of the window

@Paul_Wilkins
Okay, I think I fixed the above. Thank you for your assistance. I have one other issue, which I discussed here. Do you have any thoughts on this? It’s a pretty big problem.

<div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 106px;"> <div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 106px;"> <div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 106px;"> <div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 106px;"><

$(window).on('load', function() { $('table#comparison').each(function() { var element = $(this); var scrollWrapper = $('<div />', { 'class': 'scrollable', 'html': '<div />' }).insertBefore(element); element.data('scrollWrapper', scrollWrapper); element.appendTo(scrollWrapper.find('div')); if (element.outerWidth() > element.parent().outerWidth()) { element.data('scrollWrapper').addClass('scroll-on'); } else { $(".sticky").sticky({topSpacing:36, getWidthFrom: "#comparison", responsiveWidth: true, className: "stuck"}); } $(window).on('resize orientationchange', function() { if (element.outerWidth() > element.parent().outerWidth()) { element.data('scrollWrapper').addClass('scroll-on'); $(".sticky").unstick(); } else { element.data('scrollWrapper').removeClass('scroll-on'); $(".sticky").sticky({topSpacing:36, getWidthFrom: "#comparison", responsiveWidth: true, className: "stuck"}); } }); }); }); $(document).scroll(function () { var stickyBottom = $('.sticky').offset().top + $('.sticky').height(), scrollLimit = $('#table-cat-OfficialWebsites').offset().top; if (!$('.sticky').data('pageScroll')) { if (stickyBottom > scrollLimit) { $('.sticky').data('pageScroll', $('body').scrollTop()); $(".sticky").unstick(); } } else { if ($('body').scrollTop() < $('.sticky').data('pageScroll')) { $('.sticky').data('pageScroll', 0); $(".sticky").sticky({topSpacing:36, getWidthFrom: "#comparison", responsiveWidth: true, className: "stuck"}); } } });

I think it can be cured by making sure the code does not create a sticky wrapper more than once. Not quite sure how to do that though.