منتظر برای پایداری
منتظر ماندن برای پایداری یک عنصر (عدم انیمیشن) به مدت میلیثانیههای مشخص شده. اگر سلکتور حداقل با یک عنصر پایدار در DOM مطابقت داشته باشد، مقدار true را برمیگرداند، در غیر این صورت خطا میدهد. اگر پرچم معکوس فعال باشد، این دستور به جای آن در صورتی که سلکتور با هیچ عنصر پایداری مطابقت نداشته باشد، مقدار true را برمیگرداند.
نکته: بهتر است به جای استفاده از این دستور، انیمیشنها را غیرفعال کنید
استفاده
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
پارامترها
نام | نوع | جزئیات |
---|---|---|
options اختیاری | WaitForOptions | گزینههای waitForStable (اختیاری) |
options.timeout اختیاری | Number | زمان به میلیثانیه (مقدار پیشفرض براساس پیکربندی waitforTimeout تنظیم میشود) |
options.reverse اختیاری | Boolean | اگر true باشد، برای حالت مخالف منتظر میماند (پیشفرض: false) |
options.timeoutMsg اختیاری | String | در صورت وجود، پیام خطای پیشفرض را جایگزین میکند |
options.interval اختیاری | Number | فاصله بین بررسیها (پیشفرض: waitforInterval ) |
مثالها
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();
});
برمیگرداند
- <Boolean>
return
: true اگر عنصر پایدار باشد