给子比顶部加一个弹窗跳转,自带win和mac判断系统,很多站有的在使用这个弹窗,如果喜欢的话可以放到子比里面即可
代码部署
将下面的代码放到自定义代码=>>自定义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("https://www8l2.cn/tag/%e5%ad%90%e6%af%94%e4%b8%bb%e9%a2%98");
}).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');
})
}
© 版权声明
THE END
暂无评论内容