waitForStable
Poczekaj na element przez podaną ilość milisekund, aby był stabilny (nie animowany). Zwraca true, jeśli selektor pasuje do co najmniej jednego elementu, który jest stabilny w DOM, w przeciwnym razie wyrzuca błąd. Jeśli flaga reverse jest ustawiona na true, polecenie zamiast tego zwróci true, jeśli selektor nie pasuje do żadnych stabilnych elementów.
Uwaga: najlepiej wyłączyć animacje zamiast używać tego polecenia
Użycie
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
Parametry
Name | Type | Details |
---|---|---|
options optional | WaitForOptions | opcje waitForStable (opcjonalne) |
options.timeout optional | Number | czas w ms (domyślnie ustawiony na podstawie wartości konfiguracyjnej waitforTimeout ) |
options.reverse optional | Boolean | jeśli true, czeka na przeciwieństwo (domyślnie: false) |
options.timeoutMsg optional | String | jeśli istnieje, zastępuje domyślny komunikat o błędzie |
options.interval optional | Number | interwał między sprawdzeniami (domyślnie: waitforInterval ) |
Przykłady
index.html
<head>
<style>
div {
width: 200px;
height: 200px;
background-color: red;
}
#has-animation {
animation: 3s 0s alternate slidein;
}
@keyframes slidein {
from {
margin-left: 100%;
width: 300%;
}
to {
margin-left: 0%;
width: 100%;
}
}
</style>
</head>
<body>
<div #has-animation></div>
<div #has-no-animation></div>
</body>
waitForStable.js
it('should detect that element is instable and will wait for the element to become stable', async () => {
const elem = await $('#has-animation')
await elem.waitForStable({ timeout: 3000 });
});
it('should detect that element is stable and will not wait', async () => {
const elem = await $('#has-no-animation')
await elem.waitForStable();
});
Zwraca
- <Boolean>
return
: true jeśli element jest stabilny