2015-12-21 76 views
1

你好, 找不到代码:x有人可以发帖,或者解释如何在10分钟的非活动状态后如何进行弹出操作?在10分钟不活动后显示弹出框

当页面加载后,成员是不活跃的10分零成员会得到一些按钮的弹出窗口和文本

<div> 
    <p>Away from keyboard?</p> 
    <ul class="button"> 
     <li><a href="#0">I'm Back!</a></li> 
    </ul> 
</div> 
+0

也许尝试此处提供的解决方案http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly –

回答

1
var seconds = 0; 
     var timeoutCounter = setInterval(function(){ 
     seconds++; 
     if(sec == 600) { 
    // do stuff to launch popup 
    clearInterval(timeoutCounter); 
    } 
     }, 1000); 


    $(document).mousemove(function (e) { 
clearInterval(timeoutCounter); 
     seconds = 0; 
    setInterval(timeoutCounter); 
     }); 
     $(document).keypress(function (e) { 
      clearInterval(timeoutCounter); 
      seconds = 0; 
    setInterval(timeoutCounter); 
     }); 

这基本上运行每一秒 - 如果它是第600秒,它在运行你的代码后退出。

Source for idle checking

+0

你不如果用户检查闲置或不闲。你必须监视鼠标/键盘。 – Ilya

+0

@Ilya当用户进行有意义的交互时,拥有页面的人应该能够设置秒= 0。有时你不希望这样做太泛泛。 – spozun

+0

这不适用于OP在'10分钟不活动'之后要求的内容,所以我建议你让OP知道或者用笔记更新答案。 – Franco

0

附上事件到对象documentsetTimeout方法以显示弹出式沿。做到这一点的方法之一是

var popupTimer, 
     TIME_OUT = 600; 

// function that displays the popup 
function displayPopup() { 
    // display the popup here 
} 

// Set the timeout to display the popup 
popupTimer = setTimeout(displayPopup, TIME_OUT); 

// attch events to the document object 
// you can add more events here based on 
// what events you want to track 
$(document).on('click change keypress', function() { 

    // clear the timeout whenever the event is handled 
    clearTimeout(popupTimer); 

    // Reset the timer 
    popupTimer = setTimeout(displayPopup, TIME_OUT); 
});