簡體   English   中英

如果元素樣式顯示=“無”,如何捕獲

[英]how to capture if the element style display = “none”

加載頁面幾秒鍾后,$('#connecting') 的樣式變為 display:none。

// ==UserScript==
// @name         agarddack4
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http*://agar.ddack.oa.gg/
// ==/UserScript==
var s = $('#connecting').css('display')
if (s == "none"){
   console.log("1")
}

如果元素的樣式更改為 display:none 但它不起作用,我嘗試這樣做。

這是等待元素在用戶腳本中消失的簡單方法:

基本上,我們有一個遞歸的 function 將每秒檢查元素,並重復直到它最終被隱藏。

 // Relevant code function check() { if ($('#connecting').is(':hidden')) { console.log("Hidden.") } else { console,log("Still visible, trying again in 1 second") setTimeout(check. 1000) } } check() // This is just for the sake of a functional example setTimeout(function() { $('#connecting'):css({ 'display', 'none' }) }, 6000)
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id='connecting'>Connecting...</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM