小程序中广告组件怎么调整宽度?
发布于 5 年前 作者 chao18 3421 次浏览 来自 问答

在ad组件加style或者在wxss中修改都没有效果。

2 回复

麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

let { screenWidth } = wx.getSystemInfoSync();
ad = wx.createBannerAd({
  adUnitId:
'xxxxxxxxx',
  style: {
     left: 0,
     top: 0,
     width: 0,
     height: 0
  }
});

ad.onResize(() => {
  ad.style.width = screenWidth * 0.6;
  ad.style.left = (screenWidth - ad.style.realWidth) / 2;
  ad.style.top = screenHeight - ad.style.realHeight;
});


你把这段代码替换到你的代码中去试试

回到顶部