[英]Autohide a div if any buttons are pressed
I'm making my own video player with an info div on the top and a playbar div in the bottom. 我正在制作自己的视频播放器,顶部是一个信息div,底部是一个播放栏div。
These bars should disappear in 5 seconds if any buttons are pressed and if you press a button these bars should appear (if they are hidden) or stay for 5 seconds more. 如果按下任何按钮,这些条应在5秒钟内消失,如果您按下按钮,则这些条应出现(如果已隐藏)或停留5秒钟以上。
At first i thought in something like this 起初我以为是这样
document.onkeyup = function(event) {
showBar('playbarDiv');
showBar('infoDiv');
setTimeout(function() {
hideBar();
}, 5000);
if (hideCounter !== 1){
focusOn('playButton');
hideCounter = 1;
}
};
But of course each time a button is pressed you add a setTimeOut function to the queue, so after 5 seconds the bars starts to hide and show. 但是当然,每次按下按钮时,都会向队列添加setTimeOut函数,因此5秒钟后,条形开始隐藏和显示。
I need to avoid this with something like "restart" the SetTimeOut when i press a button instead to "load" a new. 当我按下按钮而不是“加载”新内容时,我需要使用“重新启动” SetTimeOut之类的方法来避免这种情况。
This is a simple example: Demo 这是一个简单的示例: 演示
Is this possible? 这可能吗? or I need to use something different to setTimeOut? 还是我需要使用与setTimeOut不同的东西?
Thanks in advance. 提前致谢。
Yes, it's possible, you can use window.clearTimeout(yourTimeOutVariable)
to clear previous timeouts. 是的,有可能,您可以使用window.clearTimeout(yourTimeOutVariable)
清除以前的超时。 Check your demo, updated 检查您的演示,更新
You can read more about it here http://www.w3schools.com/jsref/met_win_cleartimeout.asp 您可以在这里http://www.w3schools.com/jsref/met_win_cleartimeout.asp阅读更多有关它的信息。
Try this: 尝试这个:
jQuery(document).ready(function(){
document.onkeyup = function(event) {
if($("#content").not(":visible")){
$("#content").fadeIn(500);
setTimeout(function() { $("#content").fadeOut(500); }, 5000);
};
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.