news 2026/6/10 20:23:38

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/10 9:22:11

仅限资深开发者:C#编写高性能数字孪生渲染引擎的10个核心秘诀

第一章:工业数字孪生与C#实时渲染引擎概述工业数字孪生是智能制造和工业4.0的核心技术之一,通过构建物理设备的虚拟映射,实现对生产过程的实时监控、仿真分析与优化决策。在这一过程中,高保真度的可视化呈现至关重要,而…

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

Bili2text:重新定义视频内容处理效率

Bili2text:重新定义视频内容处理效率 【免费下载链接】bili2text Bilibili视频转文字,一步到位,输入链接即可使用 项目地址: https://gitcode.com/gh_mirrors/bi/bili2text 你是否曾经为了从视频中提取关键信息而反复回放?…

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

鸿蒙深色模式与Flutter界面联动适配指南

欢迎大家加入[开源鸿蒙跨平台开发者社区](https://openharmonycrossplatform.csdn.net),一起共建开源鸿蒙跨平台生态。鸿蒙深色模式与Flutter界面联动适配指南 在鸿蒙(HarmonyOS)应用中集成Flutter时,深色模式的适配是一个关键需…

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

天远全国自然人多头借贷风险API接口Java对接与解密工具类实现

一、构建基于天远API的金融风控中台 在构建企业级信贷审批系统或消费金融风控中台时,数据源的稳定性与集成效率至关重要。天远数据提供的“全国自然人多头借贷风险信息查询”API,通过整合银行、消金、小贷及互金平台的多维度数据,为后端决策引…

作者头像 李华
网站建设 2026/6/10 11:05:23

Playwright02-CDP

Playwright02-CDP playwright自动化开发记录,学习BrowserUse的时候涉及到playwright和udp-use的知识点 1-核心知识点 1-运行playwright第一个demo 2-参考网址 1-用Playwright实现接口自动化测试:https://www.cnblogs.com/wzzkaifa/p/191135782-playwri…

作者头像 李华