news 2026/6/23 9:58:47

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/6/23 16:28:56

Adobe官方卸载工具下载安装保姆级教程(附下载地址,非常详细)

Adobe Creative Cloud Cleaner Tool,中文常被简称为“Adobe官方卸载工具”,它并不是用来修图、剪片或做特效的新软件,而是 Adobe 自己放出的“清洁工”。 当Photoshop、Premiere、Illustrator等软件反复装不上、卸不掉,或老版本残…

作者头像 李华
网站建设 2026/6/23 9:20:41

shell笔记

shell笔记 shell shell在线工具[https://www.runoob.com/try/showbash.php?filenamehelloworld] Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。 Shell 是指一种应用程序,…

作者头像 李华
网站建设 2026/6/21 19:54:34

多头和q,kv的区别

🎯 多头(Multi-Head) 和 Q/K/V 的关系与区别 它们不是同一东西,甚至不是同一个层次的概念。 我用一句话先总结:Q/K/V 是注意力的“向量角色”,多头是把这些向量“切成多份并行处理”的技巧。再展开。&#…

作者头像 李华
网站建设 2026/6/23 6:26:32

为什么加上位置编码后 patch 会有空间信息 需要解释一下

❓为什么“把位置编码加到 patch 上”就能让模型拥有空间信息? 很多人以为:“位置编码只是几个数字,怎么就让模型知道左边右边、上下?”实际上理解这个问题,只需要搞清楚两件事: 🧠 核心机制 注…

作者头像 李华
网站建设 2026/6/23 4:28:23

基于Springboot船舶监造管理系统【附源码+文档】

💕💕作者: 米罗学长 💕💕个人简介:混迹java圈十余年,精通Java、小程序、数据库等。 💕💕各类成品Java毕设 。javaweb,ssm,springboot等项目&#…

作者头像 李华
网站建设 2026/6/22 10:37:18

从原型到产品:融合算子的单元测试、集成测试与持续集成

目录 🔍 摘要 1 🎯 融合算子测试的独特挑战与价值 1.1 为什么融合算子需要特殊测试策略 1.2 测试金字塔模型在算子开发中的实践 2 🏗️ 测试体系架构设计 2.1 多层次测试框架架构 2.2 测试环境容器化部署 3 ⚙️ 单元测试深度实战 3…

作者头像 李华