1.跳转按钮
页面设置一个浮动的按钮,显示剩余多少秒后会自动跳转到目标页面,无操作时每秒减1,同时按钮上的提示秒数也会更新
<a id="returnBtn" style="padding-top:30px;text-align: center;line-height: 40px;display: block;width: 60px;height: 150px;background: #0086c3;position: fixed;top: 480px;font-size: 25px;border: 0;border-radius: 0 25px 25px 0;color: #fff;left: 0px;">
返<br>回<br>
<span id="secondText" style="font-size:1.2rem">(120)</span>
</a>
2.js代码
window.onload = function (){
(function($){
//设置多少秒跳转
var mtReturnTime = 120;
//剩余秒数
var myTime = 120;
//定时器
window.setInterval(function(){
//设置更新按钮上的提示秒数
document.getElementById("secondText").innerHTML="("+myTime+")";
myTime--;
//0秒跳转目标页面
if(myTime==0){
window.location.href="/targetUrl";
}
},1000)
//设置各类监听事件
var body = document.querySelector('html');
body.addEventListener("click",function(){
myTime=mtReturnTime
});
body.addEventListener("keydown",function(){myTime=mtReturnTime});
body.addEventListener("mousemove",function(){myTime=mtReturnTime});
body.addEventListener("mousewheel",function(){myTime=mtReturnTime});
document.addEventListener("scroll", function(){myTime=mtReturnTime});
})(window)
}