diff --git a/src/v2/cookbook/creating-custom-scroll-directives.md b/src/v2/cookbook/creating-custom-scroll-directives.md index 12c076bb3e..db1edf57d6 100644 --- a/src/v2/cookbook/creating-custom-scroll-directives.md +++ b/src/v2/cookbook/creating-custom-scroll-directives.md @@ -1,12 +1,12 @@ --- -title: Creating Custom Scroll Directives (EN) +title: Créer une directive de défilement personnalisée type: cookbook order: 7 --- -## Base Example +## Exemple de base -
Cette page est en cours de traduction. Pour nous aider, vous pouvez participer sur le dépôt GitHub dédié de Vuejs-FR.
There are many times that we might want to add a bit of behavior, especially animation, to a scroll event on a site. There are many ways to do so, but the path with the least amount of code and dependencies is perhaps to use a [custom directive](https://vuejs.org/v2/guide/custom-directive.html) to create a hook for anything that fires off a particular scroll event.
+Plus d'une fois nous avons besoin d'introduire un comportement, en particulier d'animation, lors du défilement d'un site. Il y a plusieurs façons d'y parvenir mais le plus simple, en évitant d'accumuler les dépendances, est d'utiliser une [Directive personnalisée](https://fr.vuejs.org/v2/guide/custom-directive.html) pour créer un « hook » qui sera déclenché lors du défilement. ```js Vue.directive('scroll', { @@ -39,7 +39,7 @@ new Vue({ ```htmlRemember! The directive must be registered before the Vue instance.
+N'oubliez pas ! La directive doit être enregistrée avant la création de l'instance de Vue.
-We'd also need a style property that will transition the intermediary values here, in this case: +Nous avons également besoin d'une propriété pour calculer les valeurs intermédiaires lors de la transition, dans notre cas : ```css .box { @@ -62,7 +62,7 @@ We'd also need a style property that will transition the intermediary values herSee the Pen Custom Scroll Directive- CSS Transition by Sarah Drasner (@sdras) on CodePen.
-Or, with GreenSock(GSAP) or any other JavaScript animation library, the code becomes even more simple: +Ou, avec GreenSock(GSAP) ou toute autre librairie d'animation JavaScript, le code devient encore plus simple : ```js Vue.directive('scroll', { @@ -94,28 +94,28 @@ new Vue({ }) ``` -Though we would remove the previous CSS transition from this implementation because it's now handled with JavaScript. +Nous devons retirer la transition CSS de l'exemple précédent puisque dans cette implémentation, tout est calculé directement avec JavaScript. -## The Benefit of Using Custom Directives +## Le bénéfice de l'utilisation des directives personnalisées -Vue is rich with options for directives, most of which cover very common use-cases, which can create a very productive developer experience. But even if you have an edge case not covered by the framework, it's got you covered in this case as well, because you can quite easily create a custom directive to fit your needs. +Vue est riche en option pour les directives, ce qui permet de couvrir la majorité des cas d'utilisation, ce qui permet d'améliorer la production et l'expérience de développement. Mais pour certains « cas limite » qui ne seraient pas couverts par le framework, ce sera à vous de réaliser la directive qui répondra parfaitement à vos besoins. -Attaching and removing scroll events to elements is a really good use case for this technique because just like other directives we use, they are necessarily tied to the element and otherwise, we'd have to find the reference for it in the DOM. This pattern avoids the need for traversal, and keeps the event logic paired with the node that it's in reference to. +Ajouter et retirer des « évènements de défilement/scroll » sur un élément est un bon cas d'utilisation de cette technique, parce qu'à l'image des autres directives, elle est nécessairement liée à un élément sinon, il faudrait trouver l'élément dans le DOM. Ce modèle évite d'avoir besoin de parcourir le DOM et conserve une logique évènementielle avec le noeud auquel il fait référence. -## Real-World Example: Using a Custom Scroll Directive for Cascading Animations +## Exemple concret : Utiliser une directive de défilement personnalisée pour animer en cascade -In the course of creating a cohesive site, you may find that you're reusing the same type of animation logic in several areas. It seems simple, we would then create a very specific custom directive, right? Well, typically if you're reusing it, you will need to change it _just_ slightly for each use. +Au cours de la création de vos sites, vous constaterez que vous réutilisez régulièrement les mêmes logiques d'animation à plusieurs endroits. C'est simple, nous allons créer une directive super spécifique ? Et bien, typiquement si nous souhaitons pouvoir la réutiliser, nous devons la rendre _légèrement_ personnalisable pour chaque cas d'utilisation. -To help keep our code concise and legible, we would want to pass in some predefined arguments such as the beginning point and ending of the animation as we scroll down the page. +Afin de conserver un code concis et lisible, nous allons transmettre des arguments prédéfinis, tels que le point de départ et de fin d'animation au fur et à mesure que nous parcourons la page. -**This example is better viewed in the [full screen version](https://s.codepen.io/sdras/debug/078c19f5b3ed7f7d28584da450296cd0).** +**Cet exemple est plus visuel [en plein écran](https://s.codepen.io/sdras/debug/078c19f5b3ed7f7d28584da450296cd0).**See the Pen Scrolling Example- Using Custom Directives in Vue by Sarah Drasner (@sdras) on CodePen.
-In the demo above, each of the sections has two different types of animation triggered from the scroll: a morphing animation, and a drawing animation that animates the individual paths in the SVG. We reuse those two animations, so we can create a custom directive for each. The arguments we'll pass in will help keep everything simple and reusable. +Dans la démo ci-dessus, chacune des sections comporte deux différents types d'animations déclenchés lors du défilement : Une animation type « morphing » et une animation type « dessin » qui anime individuellement chacun des `