如何使用JS或JQuery 实现屏幕保护功能

fish_whale 2017-06-15 06:04:30
请问如何实现当用户在5分钟内没有进行点击操作时, 自动跳转到另一个页面
...全文
333 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2017-06-15
  • 打赏
  • 举报
回复
document.querySelector(".myclass").onclick = function () { document.onmousemove = null; clearTimeout(x); }
fish_whale 2017-06-15
  • 打赏
  • 举报
回复
引用 3楼天际的海浪 的回复:
[quote=引用 2 楼 fish_whale 的回复:] [quote=引用 1楼天际的海浪 的回复:]
var timer;
window.onload = document.onmousemove = document.onkeydown = function () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		window.location.href = "xxxx.html";
	}, 5*60*1000);
}
请问如果中途我不需要这个屏幕保护功能了,应该如何停止这个函数的调用呢[/quote] document.onmousemove = document.onkeydown = null; clearTimeout(timer); [/quote]请问如果用下面这种方法 要怎么做到在点击页面上红色的div 时停止屏幕保护函数的调用 <!DOCTYPE html> <html> <head> <title>等待测试</title> </head> <body> <div class="myclass" style="width:100px; height:100px; background:red;"></div> <script> var x; window.onload = init; function init() { //设置,页面载入完毕之后,1秒不懂鼠标就页面就会跳转 x = setTimeout("location.href = 'add.html'", 3000); //鼠标在网页上移动调用moved函数 document.onmousemove = moved; } function moved() { //既然鼠标移动了,取消页面跳转 clearTimeout(x); //从现在开始重新计时,如果到了1秒还是要跳转 x = setTimeout("location.href = 'add.html'", 3000); } </script> </body> </html>
天际的海浪 2017-06-15
  • 打赏
  • 举报
回复
引用 2 楼 fish_whale 的回复:
[quote=引用 1楼天际的海浪 的回复:]
var timer;
window.onload = document.onmousemove = document.onkeydown = function () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		window.location.href = "xxxx.html";
	}, 5*60*1000);
}
请问如果中途我不需要这个屏幕保护功能了,应该如何停止这个函数的调用呢[/quote] document.onmousemove = document.onkeydown = null; clearTimeout(timer);
fish_whale 2017-06-15
  • 打赏
  • 举报
回复
引用 1楼天际的海浪 的回复:
var timer;
window.onload = document.onmousemove = document.onkeydown = function () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		window.location.href = "xxxx.html";
	}, 5*60*1000);
}
请问如果中途我不需要这个屏幕保护功能了,应该如何停止这个函数的调用呢
天际的海浪 2017-06-15
  • 打赏
  • 举报
回复
var timer;
window.onload = document.onmousemove = document.onkeydown = function () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		window.location.href = "xxxx.html";
	}, 5*60*1000);
}

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧