【发布时间】:2017-08-09 09:28:55
【问题描述】:
我在使用sticky-kit v1.1.2 的测试页面上显示了一些 AdSense 广告。
当我向下滚动页面时(我使用的是 Chrome 浏览器),当粘性工具包变得粘性时,广告会闪烁/重新加载。
我已阅读此trouble shooting guide,它似乎确实解决了我遇到的确切问题,但不适用于我的代码。
我的代码如下所示。我故意省略了以下两个 div,因为我不确定它们应该插入到哪里(我尝试了很多场景,但没有一个适合我):
<div class="sticky-parent">
<div class="sticky-spacer">
</div>
</div>
这是我的 HTML 代码:
<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>
这是我的 JQ 代码:
// 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');
})
【问题讨论】:
-
在
sticky_kit:unbottom事件回调期间,可能将position设置为inherit而不是relative,以防父css没有'它的position之前设置为relative -
我认为您想将
class="sticky-parent"添加到id_side_advert_container并将带有class="margin-bottom-20"的div 更改为class="margin-bottom-20 sticky-spacer"。 -
尝试将
will-change: margin添加到#id_side_advert_container的CSS。这在过去为我解决了一些性能故障。 -
我看不到它是否闪烁,尝试使用虚拟客户端 id
ca-digitalinspiration创建 jsfiddle
标签: javascript jquery sticky