JS弹窗引导提醒

教程简介:

给子比顶部加一个弹窗跳转,自带win和mac判断系统,很多站有的在使用这个弹窗,如果喜欢的话可以放到子比里面即可

相关图片:

WordPress和子比主题模板&子比主题美化合集教程-彩豆博客

教程如下:

此处隐藏内容

将下面的代码放到自定义代码=>>自定义javascript代码

 
 
 
// 判断存在jq资源
try {
if($ || jQuery) {
tipsFun();
}
} catch(e) {
let script=document.createElement(“script”);
script.type=“text/javascript”;
script.src=“https://cdn.mac89.com/common/static/jquery.min.js”;
 
document.getElementsByTagName(‘head’)[0].appendChild(script);
 
script.onload = tipsFun;
}
 
 
function tipsFun() {
// 判断用户是否是windows
if((navigator.platform == “Win32”) || (navigator.platform == “Windows”)) {
// let hostName = location.hostname;
// if(hostName === ‘mac.mac89.com’) return;
 
let curTime = new Date().getTime();
if(!window.localStorage.hasTips || ((curTime – window.localStorage.hasTips) >= 86400000)) {
setTimeout(()=> {
$(document).ready(function(){
let tipHtml = `
<div class=“tip-box” id=“tip-box” style=“position: fixed; z-index: 9999; width: 740px; height: 150px; background-color: #fff; border-radius: 0 0 20px 20px; text-align: center; font-size: 16px; top: 0; left: 50%; margin-left: -370px; box-shadow: 0 10px 20px 0 rgba(0, 0, 0, 0.2); display: none; transform: translateY(-100%); transition: all .6s;”>
<p class=“tip” style=“font-size: 18px; line-height: 1; margin: 38px 0 22px;”>欢迎来到荻酷网,如果需要更多美化点击前往</p>
<button class=“nomore” style=“width: 120px; cursor: pointer; height: 40px; border: 1px solid #ddd; outline: none; border-radius: 5px; margin-right: 40px;”>不再提醒</button>
<button class=“cancel” style=“background-color: #333; color: #fff; width: 120px; cursor: pointer; height: 40px; border: none; outline: none; border-radius: 5px; margin-right: 40px;”>继续浏览</button>
<button class=“sure” style=“height: 40px; padding: 0 30px; background-color: #1B78F5; cursor: pointer; color: #fff; border-radius: 5px; outline: none; border: none;”>立即前往 (10)</button>
</div>`;
 
$(‘body’).append(tipHtml);
 
const $tipBox = $(‘#tip-box’);
$tipBox.show().css(‘transform’, ‘translateY(0)’);
 
$tipBox.on(‘click’, ‘.cancel’, ()=> {
removeTip();
}).on(‘click’, ‘.sure’, ()=> {
window.open(“前往地址”);
}).on(‘click’, ‘.nomore’, ()=> {
removeTip();
window.localStorage.hasTips = curTime;
})
 
let time = 10, timer;
 
timer = setInterval(()=> {
time–;
$tipBox.find(‘.sure’).text(‘立即前往 (‘+ time +‘秒)’)
if(time < 1) {
removeTip();
}
}, 1000)
 
function removeTip() {
$tipBox.css(‘transform’, ‘translateY(-100%)’);
clearInterval(timer);
setTimeout(function() {
$tipBox.remove();
}, 600)
}
});
}, 1000);
}
}
$(‘#shop-box’).on(‘click’, ‘.close’, function() {
let $box = $(‘#shop-box’)
if($box.hasClass(‘bot’)) {
$box.css({‘bottom’: ‘0’})
$(this).css({‘transform’: ‘rotate(0)’})
window.localStorage.hideShop = ;
} else {
$box.css({‘bottom’: ‘-117px’})
$(this).css({‘transform’: ‘rotate(180deg)’})
window.localStorage.hideShop = ‘hide’;
}
 
$box.toggleClass(‘bot’);
})
}
温馨提示:本文最后更新于2024-05-08 06:16:05,某些文章具有时效性,若有错误或已失效,请在下方留言
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

夸夸
还有吗!没看够!
取消
昵称表情代码图片

    暂无评论内容