Google pubads出现然后消失

Amb*_*erg 9 javascript jquery sticky adsense gpt

我正在http://development-client-server.com/ds/上使用Google pubads,这是很有效的,直到你进入实际的故事页面(见http://development-client-server.com/ds/)当右上边栏广告加载然后快速消失时,语音更常见的自闭症/).

我把它缩小到我用来粘贴左边的社交媒体栏和右侧的工作列表div(在Google广告所在的位置下)的stickySidebars功能.但是,粘性功能应该不会影响Google广告吗?

这是我正在使用的JS函数,我已经多次重写了(并且已经尝试与客户讨论已经使用过).

<script>

// Sticky Sidebars

function stickySidebars() {   

    var length = $('.post-content').height() - $('article .sharing-links').height() + $('.post-content').offset().top;
    var lengthSidebar = $('.sticky-container').height() - $('aside .job-listings').height() + $('.sticky-container').offset().top -30;

    $(window).scroll(function () {

        // Sharing Links

        var scroll = $(this).scrollTop() + 90;
        var height = $('article .sharing-links').height() + 'px';

        if (scroll < $('.post-content').offset().top) {

            $('article .sharing-links').css({
                'position': 'absolute',
                'top': 'auto',
                'bottom': 'auto'
            });

        } else if (scroll > length) {

            $('article .sharing-links').css({
                'position': 'absolute',
                'bottom': '0',
                'top': 'auto'
            });

        } else {

            $('article .sharing-links').css({
                'position': 'fixed',
                'top': '90px',
                'height': height
            });

        }

        // Sidebar

        var heightSidebar = $('aside .job-listings').height() + 'px';

        if (scroll < $('aside .job-listings').offset().top) {

            $('aside .job-listings').css({
                'position': 'absolute',
                'top': '300px',
                'bottom': 'auto'
            });

        } else if (scroll > lengthSidebar) {

            $('aside .job-listings').css({
                'position': 'absolute',
                'bottom': '30px',
                'top': 'auto'
            });

        } else {

            if (scroll < $('.sticky-container').offset().top + 300) {

                $('aside .job-listings').css({
                    'position': 'absolute',
                    'top': '300px',
                    'bottom': 'auto'
                });

            } else {

                $('aside .job-listings').css({
                    'position': 'fixed',
                    'top': '90px',
                    'height': heightSidebar
                });
            }

        }
    });
}

$(window).on('load',function(){
    if($(window).width() > 1100){
        stickySidebars();
    } 
});

$(window).resize(function() {
    if($(window).width() > 1100){
        stickySidebars();
    }
});
</script>
Run Code Online (Sandbox Code Playgroud)

tw1*_*w16 7

该问题不是由粘性侧边栏引起的.它是由这段代码引起的:

$(window).on('load',function(){
    // Other unrelated functions here...

    /*****************************/
    // Move Sidebar in Mobile
    /*****************************/

    if($(window).width() <= 980){
        $("aside").appendTo(".mobile-sidebar");
    } else {
        $("aside").insertAfter(".single-article article");
    }
});
Run Code Online (Sandbox Code Playgroud)

基本上广告加载然后移动容器(the aside),这会导致广告消失.

有一些不同的选项,但基本上您需要在该段代码之后运行Google广告脚本,或者您需要刷新广告.要刷新广告,您应该能够在if else语句后直接运行此行代码:

googletag.pubads().refresh()
Run Code Online (Sandbox Code Playgroud)

这会刷新所有广告.根据您的设置方式,您可以传入一个变量,refresh()以便刷新特定广告,例如

var slot1 = googletag.pubads().display('/1234567/sports', [728, 90], 'div-1');

googletag.pubads().refresh([slot1]);
Run Code Online (Sandbox Code Playgroud)

用于刷新的Google参考文档()