news 2026/9/5 23:04:33

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/5 17:31:19

四份 AI Agent 报告大比拼:为什么 AiPy 自研模型更懂行业?

最近 AI Agent 赛道热度飙升,不少朋友都在用工具生成行业报告做参考。今天我们拿三份用 AiPy 对接不同模型生成的报告做对比,看看它们各有什么特点,以及为什么 AiPy 自研模型的输出更值得关注。先看效果qwen:Claude:AiPy:Deepseek:先上核心对…

作者头像 李华
网站建设 2026/9/5 15:37:42

闲鱼自动化终极解决方案:5分钟实现高效运营管理

闲鱼自动化终极解决方案:5分钟实现高效运营管理 【免费下载链接】xianyu_automatize [iewoai]主要用于实现闲鱼真机自动化(包括自动签到、自动擦亮、统计宝贝数据) 项目地址: https://gitcode.com/gh_mirrors/xia/xianyu_automatize 还…

作者头像 李华
网站建设 2026/9/6 6:34:22

用这套源码系统,轻松将静态图片变成交互式相册

温馨提示:文末有资源获取方式企业的宣传材料若仅停留在静态的PDF或图片集层面,极易在信息洪流中被淹没。客户渴望更生动、更便捷、更具互动性的了解方式。因此,将传统的产品图册、公司介绍转化为一个可在线访问、多媒体融合、并便于分享的“数…

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

STM32 架构概述

目录 一、STM32 架构的核心层级(从上到下) 二、核心:Cortex-M 内核架构(以 M3 为例) 关键补充:Cortex-M 内核的指令集 三、核心骨架:片上总线架构 1. 总线层级(从高速到低速&am…

作者头像 李华
网站建设 2026/9/6 6:07:31

大批量网页替换工具

## 功能特点1. ✅ 选择文件夹,递归遍历所有子文件夹2. ✅ 支持多种文件类型:.html .htm .shtml .php .asp .aspx .jsp .css .js3. ✅ 查找替换文本,支持区分大小写选项4. ✅ 替换前自动备份到 _backup 文件夹5. ✅ 实时显示进度条和处理进度6…

作者头像 李华