scrollIntoView
Faire défiler l'élément dans la zone visible pour les applications Web Desktop/Mobile ET les applications natives mobiles.
info
Le défilement pour les applications natives mobiles est effectué à l'aide de la commande mobile swipe.
Utilisation
$(selector).scrollIntoView({ behavior, block, inline, direction, maxScrolls, duration, scrollableElement, percent })
Paramètres
| Nom | Type | Détails |
|---|---|---|
optionsoptionnel | object, boolean | options pour Element.scrollIntoView(). Par défaut pour desktop/mobile web: { block: 'start', inline: 'nearest' } Par défaut pour les applications natives mobiles { maxScrolls: 10, scrollDirection: 'down' } |
| Desktop/Mobile Web Uniquement | ||
options.behavioroptionnel | string | Voir Référence MDN. WEB-UNIQUEMENT (Desktop/Mobile) |
options.blockoptionnel | string | Voir Référence MDN. WEB-UNIQUEMENT (Desktop/Mobile) |
options.inlineoptionnel | string | Voir Référence MDN. WEB-UNIQUEMENT (Desktop/Mobile) |
| Applications Natives Mobiles Uniquement | ||
options.directionoptionnel | string | Peut être down, up, left ou right, par défaut c'est up. APPLICATION-NATIVE-MOBILE-UNIQUEMENT |
options.maxScrollsoptionnel | number | Le nombre maximum de défilements avant d'arrêter la recherche de l'élément, par défaut c'est 10. APPLICATION-NATIVE-MOBILE-UNIQUEMENT |
options.durationoptionnel | number | La durée en millisecondes pour le balayage. Par défaut, c'est 1500 ms. Plus la valeur est basse, plus le balayage est rapide.APPLICATION-NATIVE-MOBILE-UNIQUEMENT |
options.scrollableElementoptionnel | Element | Élément utilisé pour faire défiler. Si aucun élément n'est fourni, il utilisera le sélecteur suivant pour iOS -ios predicate string:type == "XCUIElementTypeApplication" et le suivant pour Android //android.widget.ScrollView'. Si plusieurs éléments correspondent au sélecteur par défaut, il choisira par défaut le premier élément correspondant. APPLICATION-NATIVE-MOBILE-UNIQUEMENT |
options.percentoptionnel | number | Le pourcentage de l'élément défilable (par défaut) à balayer. C'est une valeur entre 0 et 1. Par défaut c'est 0.95.NE JAMAIS balayer depuis l'exact haut|bas|gauche|droite de l'écran, vous pourriez déclencher par exemple la barre de notification ou d'autres fonctionnalités OS/App ce qui peut mener à des résultats inattendus. APPLICATION-NATIVE-MOBILE-UNIQUEMENT |
Exemples
desktop.mobile.web.scrollIntoView.js
it('should demonstrate the desktop/mobile web 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' });
});
mobile.native.app.scrollIntoView.js
it('should demonstrate the mobile native app scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to a specific element in the default scrollable element for Android or iOS for a maximum of 10 scrolls
await elem.scrollIntoView();
// Scroll to the left in the scrollable element called '#scrollable' for a maximum of 5 scrolls
await elem.scrollIntoView({
direction: 'left',
maxScrolls: 5,
scrollableElement: $('#scrollable')
});
});