news 2026/8/25 9:10:37

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/8/24 20:30:26

线性回归+实例

线性回归是统计学和机器学习中最基础的回归分析方法,核心目标是构建自变量(特征)与连续型因变量(标签)之间的线性关系模型,通过拟合最优直线 / 超平面,实现对连续值的预测。以下是从核心定义到应…

作者头像 李华
网站建设 2026/8/24 10:42:53

你还在手动排查量子代码?VSCode Azure QDK自动调试方案曝光

第一章:量子编程调试的现状与挑战 量子计算正逐步从理论走向工程实践,但其编程与调试仍面临诸多独特挑战。传统经典程序可通过断点、日志和变量检查进行调试,而量子态的叠加性、纠缠性和不可克隆性使得这些方法无法直接沿用。 量子态的观测限…

作者头像 李华
网站建设 2026/8/24 17:52:31

HMI背后的显控技术正在发生变化

过去十多年,我用小型的OLED12864显示屏做过智能门锁,也用10多寸显示屏做过医疗器械产品。这些年,HMI(人机界面)已经融入到我们生活的方方面面。第四次工业革命已经到来,传统的机械式仪表正在被更先进的 HMI…

作者头像 李华
网站建设 2026/8/24 14:28:57

推镜镜头 Motion LoRA:为 Wan 2.1 模型注入电影级动态视觉体验

推镜镜头 Motion LoRA:为 Wan 2.1 模型注入电影级动态视觉体验 【免费下载链接】Motion-Lora-Camera-Push-In-Wan-14B-720p-I2V 项目地址: https://ai.gitcode.com/hf_mirrors/lovis93/Motion-Lora-Camera-Push-In-Wan-14B-720p-I2V 在当今的 AI 视频生成领域…

作者头像 李华