急!小游戏的realHeight取不到值 迫使广告无法底部对齐贴边?
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 回复