somewebmedia / hc-sticky

JavaScript library that makes any element on your page visible while you scroll.
https://somewebmedia.github.io/hc-sticky/
MIT License
462 stars 114 forks source link

Google ad (adsense) iframes sometimes disappear when in a sticky container. #22

Closed tbartels closed 7 years ago

tbartels commented 9 years ago

RE: http://someweblog.com/hcsticky-jquery-floating-sticky-plugin/#div-comment-14461 (for some reason your webhost firewall has decided to block me for trying to submit this as a comment)

I've been battling this same thing for the past week. I think I have found the problem as well as a partial solution.

The basic issue is that ALL iframes don't "like" DOM manipulations, if an iframe is inside a node that is removed, moved or detached, the iframe will be forced to reload. In some cases where google uses a default state of an empty iframe to write content into later this will result in the iframe being reloaded to empty content.

The fix is to avoid removing or detaching the container holding the iframes, this is not the default case for hcSticky. To fix the issue you will need to add an extra container around your content and prevent the insertion of the wrapper by adding it into your HTML.

essentially I had to convert this:

<div class="sidebar">
  content
</div>
<script>jQuery('.sidebar').hcSticky();</script>

into this:

<div class="sidebar wrapper-sticky">
  <div class="stick-me">
    content
  </div>
</div>
<script>jQuery('.sidebar .stick-me').hcSticky();</script>

Hope this helps.

Obviously this is only one way of doing it, based on the available configurations for hcSticky there are many other ways of handling this, but it boils down to preventing the automatic insertion of the wrapper by hcSticky.

djvdorp commented 9 years ago

Thank you so much for this, we are facing the exact same issue here!

ALTELMA commented 8 years ago

Hi, I will facing same problem and try your solution still don't working.

Nrohtgnohp commented 8 years ago

Me too.

ALTELMA commented 8 years ago

After I spend more time to read your instruction and try again. It work!!

Priler commented 8 years ago

Thanks, this worked fine. But, what I've done, is just wrapped my <div id="sidebar"></div> with .wrapper-sticky class like this <div class="wrapper-sticky"><div id="sidebar"></div></div> and this worked fine.

somewebmedia commented 7 years ago

Obsolete. New major version available.