sticky-kit flashes when sticky

Viewed 3258

I have some adsense ads displayed on a test page using sticky-kit v1.1.2.

When I scroll down the page (I am using Chrome browser), the ads flash/reload when the sticky-kit becomes sticky.

I have read this trouble shooting guide that does seems to address the exact issue that I am experiencing, but does not work for my code.

My code is displayed below. I have deliberately left out the two following div's, because I am unsure where they should be inserted (I have tried many scenarios, but none work for me):

<div class="sticky-parent">
  <div class="sticky-spacer">
  </div>
</div>

Here is my HTML code:

<div id="id_side_advert_container" class="side_advert col-md-2">
    <div class="margin-bottom-20">

        <div id="id_side_advert_wrapper">
            {# google adsense code to display side advertiements #}
            <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- zoodal-side-advertisement-responsive -->
            <ins class="adsbygoogle"
                 style="display:block"
                 data-ad-client="ca-pub-1234567890112987"
                 data-ad-slot="1234567890"
                 data-ad-format="auto"></ins>
            <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</div>

Here is my JQ code:

// sticky-kit code for the side advertising sticky - with an offset of 15px when sticky.
$("#id_side_advert_container").stick_in_parent({
    offset_top: 15,
    parent: ".sticky-parent", // note: we must now manually provide the parent
    spacer: ".sticky-spacer",
});

// the following code is the workaround so that the sticky element does not disappear when bottom -
// taken from: https://github.com/leafo/sticky-kit/issues/31 danxshap
$('#id_side_advert_container')
.on('sticky_kit:bottom', function(e) {
    $(this).parent().css('position', 'static');
})
.on('sticky_kit:unbottom', function(e) {
    $(this).parent().css('position', 'relative');
})
2 Answers
Related