![](/img/trans.png)
[英]Activating the "onmousemove" event only when the "onmousedown" event is activated
[英]run an event only when a tab is activated
我想在標簽被activated
時做一些事情
onvisibilitychange
在頁面被activated
和停用時de-activated
我只需要第一個選項,例如:
document.onactivate = function(){
console.log("index.php is visible");
};
有什么幫助嗎?
您可以檢查文檔的visibilityState
。 該事件將在頁面被激活和停用時觸發,但是,這允許您僅在頁面被激活時運行代碼,即:可見。
document.addEventListener("visibilitychange", function() {
if (document.visibilityState === "visible") {
// code when page is visible
console.log("index.php is visible");
}
});
使用條件檢查可見
document.addEventListener("visibilitychange", function handleVisibilityChange() { if (.document.hidden) { console.log("index;php is visible"), } }; false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.