vue2手机APP项目添加开屏广告或者闪屏广告
发布时间:2020-12-17 02:41:55 所属栏目:百科 来源:网络整理
导读:一般项目里,有的会在启动的时候加开屏广告或者闪屏广告。我们是在index.html通过定位来做的。如下: 然后我们需要单独写一份js文件,跟main.js是同级目录的,具体代码如下: { let keyArr = []; for (let key in res.data) { keyArr.push(key); } if (keyAr
一般项目里,有的会在启动的时候加开屏广告或者闪屏广告。我们是在index.html通过定位来做的。如下: 然后我们需要单独写一份js文件,跟main.js是同级目录的,具体代码如下: {
let keyArr = [];
for (let key in res.data) {
keyArr.push(key);
}
if (keyArr.length == 0) {
return;
}
openAdv(res);
});
} else {
// 分享页面中 原生入口
// 查看query中是否带有token,进行登录判断并将token存入vuex
if (query.TOKEN != '' && query.TOKEN != 'null') {
store.dispatch('storeToken',query.TOKEN);
}
}
} else {
// 不是分享页面的入口
api.commonApi('后台接口','传参数')
.then(res => {
let keyArr = []
for (let key in res.data) {
keyArr.push(key);
}
if (keyArr.length == 0) {
return;
}
openAdv(res);
});
}
function openAdv(res) {
entryAdv.style.display = 'block';
document.body.style.overflowY = 'hidden';
// 阻止滑动执行
document.body.ontouchmove = function(ev) {
ev.preventDefault();
};
let list = res.data.retList;
if (list && list.length == 0) {
entryAdv.style.display = 'none';
document.body.style.overflow = 'auto';
document.body.ontouchmove = function(ev) {
ev.stopPropagation();
};
}
let time = (res.data.SPJG || 5000) / 1000;
// let time = res.data.SPJG;
let ADV_list = [];
let BCcontextPathSrc = store.state.common.BCcontextPathSrc;
switch (res.data.ADV_TYPE) {
// 开屏直接跳过
case '1':
{
let ImgList = [];
for (let i = 0; i < list.length; i++) {
ImgList.push(BCcontextPathSrc + res.data.retList[i].ADV_IMG_URL);
ADV_list.push(res.data.retList[i].ADV_URL);
}
let count_down = time / list.length;
let ImgNum = 0;
let timer = setInterval(() => {
switch (ImgList.length) {
case 1:
break;
case 2:
{
if (time % 3 == 0) {
ImgNum++;
}
}
break;
case 3:
{
if (time % 2 == 0) {
ImgNum++;
}
}
break;
case 4:
{
if (time % 1 == 0) {
if (ImgNum > ImgList.length - 2) break;
ImgNum++;
}
}
break;
default:
{
if (time % 1 == 0) {
if (ImgNum > ImgList.length - 2) break;
ImgNum++;
}
}
break;
}
if (time <= 0) {
clearInterval(timer);
entryAdv.style.display = 'none';
document.body.style.overflowY = 'auto';
document.body.ontouchmove = function(ev) {
ev.stopPropagation();
};
}
entry.src = ImgList[ImgNum];
entryTim.innerHTML = '跳过 ' + time + 's';
entry.addEventListener('click',function() {
window.location.href = ADV_list[ImgNum];
},false);
time--;
},1000);
entryTim.addEventListener('click',function(ev) {
ev.preventDefault();
clearInterval(timer);
entryAdv.style.display = 'none';
document.body.style.overflowY = 'auto';
document.body.ontouchmove = function(ev) {
ev.stopPropagation();
};
},false);
}
break;
// 闪屏广告
case '2':
同上开屏广告,可根据贵公司要求来更改
}
};
setTimeout(() => {
require('./main.js');
},300)
这样就完成了。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |