急!小游戏的realHeight取不到值 迫使广告无法底部对齐贴边?
发布于 7 年前 作者 guiying05 7014 次浏览 来自 问答
let stageW: number = Laya.Browser.clientWidth;
        let stageH: number = Laya.Browser.clientHeight;
        if(!this.adWidth)
            this.adWidth = stageW;
        if (Laya.Browser.onMiniGame) {
            if (!BannerAd._ad) {
                let wx = Laya.Browser.window.wx;
                let ad = wx.createBannerAd({
                    adUnitId: 'adunit-b8de22bfb625f2cc',
                    adIntervals: 30,//自动刷新时间
                    style: {
                        left: (stageW - this.adWidth)/2,
                        top: stageH - 90,
                        width: this.adWidth
                    }
                });

                ad.onResize(() => {
                    ad.style.left = (stageW - this.adWidth)/2;
                    ad.style.top = stageH - ad.style.realHeight;
                });

                ad.onError(err => {
                    console.log(err);
                })
                BannerAd._ad = ad;
            }else{
                console.log("广告宽度::",stageW,this.adWidth);
                BannerAd._ad.style.left = (stageW - this.adWidth)/2;
                BannerAd._ad.style.width = this.adWidth;
                        /**********************这里这里这这里这里这这里这里这这里这里这这里这里这这里这里这这里这里这里*********************/
                BannerAd._ad.style.top = stageH - BannerAd._ad.style.realHeight;//就是这里出现这个realHeight取不到
            }
            BannerAd._ad.show();
        }
2 回复

你好,小游戏相关问题麻烦在小游戏专区提问,我们有专门的人员处理

小游戏专区:https://developers.weixin.qq.com/community/minigame

BannerAd._ad.style.clientHeight:undefined

回到顶部