waitForStable
Attendi che un elemento sia stabile (non in animazione) per il numero di millisecondi fornito. Restituisce true se il selettore corrisponde ad almeno un elemento stabile nel DOM, altrimenti genera un errore. Se il flag reverse è true, il comando restituirà invece true se il selettore non corrisponde a nessun elemento stabile.
Nota: è meglio disabilitare le animazioni invece di utilizzare questo comando
Utilizzo
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
Parametri
| Nome | Tipo | Dettagli |
|---|---|---|
optionsopzionale | WaitForOptions | opzioni waitForStable (opzionale) |
options.timeoutopzionale | Number | tempo in ms (predefinito basato sul valore di configurazione waitforTimeout) |
options.reverseopzionale | Boolean | se true attende l'opposto (predefinito: false) |
options.timeoutMsgopzionale | String | se esiste sovrascrive il messaggio di errore predefinito |
options.intervalopzionale | Number | intervallo tra i controlli (predefinito: waitforInterval) |
Esempi
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();
});
Restituisce
- <Boolean>
return: true se l'elemento è stabile