跳至主要內容

scrollIntoView

將元素滾動到視窗中(MDN 參考)。

用法
$(selector).scrollIntoView(scrollIntoViewOptions)
參數
名稱類型詳細資訊
scrollIntoViewOptionsobject, booleanElement.scrollIntoView() 的選項 (預設值:{ block: 'start', inline: 'nearest' })
範例
scrollIntoView.js
it('should demonstrate the scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to specific element
await elem.scrollIntoView();
// center element within the viewport
await elem.scrollIntoView({ block: 'center', inline: 'center' });
});

歡迎!我能幫上什麼忙嗎?

WebdriverIO AI Copilot