news 2026/9/3 0:07:26

4399小程序banner广告和插屏广告

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
4399小程序banner广告和插屏广告

banner广告

// 获取真机设备像素比 const pixelRatio = gamebox.getSystemInfoSync().pixelRatio; // 定义 Banner 广告的宽高和位置 const width = 320 * pixelRatio; const height = 50 * pixelRatio; const bannerLeft = (gamebox.getSystemInfoSync().screenWidth * pixelRatio - width) / 2; const bannerTop = gamebox.getSystemInfoSync().screenHeight * pixelRatio - height; let currentBannerAd = null; function createBannerAd() { return gamebox.createBannerAd({ style: { width: width, height: height, left: bannerLeft, top: bannerTop } }); } function showBannerAd() { if (currentBannerAd) { currentBannerAd.destroy(); // 销毁之前的 Banner 实例 } currentBannerAd = createBannerAd(); // 监听 Banner 广告加载事件回调函数 const bannerOnLoadCb = (res) => { console.info('Banner onLoad', res); }; // 监听 Banner 广告错误事件回调函数 const bannerOnErrorCb = (res) => { console.info('Banner onError', res); }; // 监听 Banner 广告加载事件 currentBannerAd.onLoad(bannerOnLoadCb); // 取消监听 Banner 广告加载事件(监听取消的函数,应与监听回调函数为同一个) currentBannerAd.offLoad(bannerOnLoadCb); // 监听 Banner 广告错误事件 currentBannerAd.onError(bannerOnErrorCb); // 取消监听 Banner 广告错误事件(监听取消的函数,应与监听回调函数为同一个) currentBannerAd.offError(bannerOnErrorCb); // 显示 Banner 广告 currentBannerAd.show().catch(err => { console.info('Banner 广告显示失败', err); }); } // 初始展示 Banner 广告 showBannerAd(); // 设置定时器,每2分钟重新展示 Banner 广告 setInterval(showBannerAd, 2 * 60 * 1000);

插屏广告

// 创建插屏广告实例 const interstitialAd = gamebox.createInterstitialAd(); // 监听 InterstitialAd 广告加载事件回调函数 const onLoadCb = (res) => { console.info('InterstitialAd onLoad ' + res); } // 监听 InterstitialAd 广告关闭事件回调函数 const onCloseCb = (res) => { console.info('InterstitialAd onClose ' + res); } // 监听 InterstitialAd 广告错误事件回调函数 const onErrorCb = (res) => { console.info('InterstitialAd onError ' + res); } // 监听 InterstitialAd 广告加载事件 interstitialAd.onLoad(onLoadCb); // 取消监听 InterstitialAd 广告加载事件(监听取消的函数,应与监听回调函数为同一个) interstitialAd.offLoad(onLoadCb); // 监听 InterstitialAd 广告关闭 interstitialAd.onClose(onCloseCb); // 取消监听 InterstitialAd 广告关闭(监听取消的函数,应与监听回调函数为同一个) interstitialAd.offClose(onCloseCb); // 监听 InterstitialAd 广告错误 interstitialAd.onError(onErrorCb); // 取消监听 InterstitialAd 广告错误(监听取消的函数,应与监听回调函数为同一个) interstitialAd.offError(onErrorCb); // 定义一个函数用于显示广告 function showInterstitialAd() { interstitialAd.show().catch(() => { // 失败重试 interstitialAd.load() .then(() => interstitialAd.show()) .catch(err => { console.log('InterstitialAd 广告显示失败', err); }); }); } // 设置一个定时器,每6分钟显示一次广告 setInterval(showInterstitialAd, 6 * 60 * 1000); // 6分钟转换为毫秒 // 销毁 InterstitialAd 广告 // interstitialAd.destroy(); // 如果需要在某些情况下销毁广告可以调用此方法
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/2 22:13:14

揭秘空间转录组数据分析:如何用R语言完成单细胞分辨率下的精准定位

第一章:揭秘空间转录组数据分析:从单细胞到空间定位空间转录组技术的出现,彻底改变了我们对组织微环境的理解。它不仅保留了单细胞分辨率的基因表达信息,还精确记录了每个细胞在组织中的物理位置,从而实现了“哪里表达…

作者头像 李华
网站建设 2026/9/2 9:48:03

全面掌控硬件性能:Universal x86 Tuning Utility深度调优攻略

全面掌控硬件性能:Universal x86 Tuning Utility深度调优攻略 【免费下载链接】Universal-x86-Tuning-Utility Unlock the full potential of your Intel/AMD based device. 项目地址: https://gitcode.com/gh_mirrors/un/Universal-x86-Tuning-Utility Univ…

作者头像 李华
网站建设 2026/9/2 3:55:55

Wan2.2-T2V-A14B在智慧农业监控回放重构中的补全能力

Wan2.2-T2V-A14B在智慧农业监控回放重构中的补全能力智慧农业的“视觉断点”困局 在一片广袤的水稻田上,无人机正按预设航线喷洒叶面肥。突然,监控画面中断了十分钟——可能是4G信号波动,也可能是边缘设备存储异常。等到运维人员调取录像时&a…

作者头像 李华
网站建设 2026/9/2 6:58:28

有什么近视防控的办法是切实有效,并且家长真的能「落地执行」的?

对于家长而言,近视防控最棘手的并非知晓“该做什么”,而是找到“能坚持做”的方法。很多理论上有效的措施,往往因需要额外付出大量时间、孩子不配合或操作复杂而难以落地。一、核心手段:眼调节训练灯 —— 照明即训练,…

作者头像 李华
网站建设 2026/9/2 21:23:26

WebRTC 信号槽机制:当 C++ 遇上观察者模式,代码解耦的优雅之道

WebRTC 信号槽机制:当 C 遇上观察者模式,代码解耦的优雅之道 本文所有源码均基于 WebRTC M85 (branch-heads/4183) 版本进行分析。 一、引言:一个让人困惑的 connect 调用 在阅读 WebRTC 源码时,你可能会频繁遇到这样的代码&…

作者头像 李华