You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/v2/cookbook/creating-custom-scroll-directives.md
+21-21
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
-
title: Creating Custom Scroll Directives (EN)
2
+
title: Créer une directive de défilement personnalisée
3
3
type: cookbook
4
4
order: 7
5
5
---
6
6
7
-
## Base Example
7
+
## Exemple de base
8
8
9
-
<p>Cette page est en cours de traduction. Pour nous aider, vous pouvez participer sur <ahref="https://github.com/vuejs-fr/vuejs.org"target="_blank">le dépôt GitHub dédié de Vuejs-FR</a>.</p><p>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.</p>
9
+
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.
10
10
11
11
```js
12
12
Vue.directive('scroll', {
@@ -39,7 +39,7 @@ new Vue({
39
39
40
40
```html
41
41
<divid="app">
42
-
<h1class="centered">Scroll me</h1>
42
+
<h1class="centered">Faites-moi défiler</h1>
43
43
<div
44
44
v-scroll="handleScroll"
45
45
class="box"
@@ -49,9 +49,9 @@ new Vue({
49
49
</div>
50
50
```
51
51
52
-
<pclass="tip">Remember! The directive must be registered before the Vue instance.</p>
52
+
<pclass="tip">N'oubliez pas ! La directive doit être enregistrée avant la création de l'instance de Vue.</p>
53
53
54
-
We'd also need a style property that will transition the intermediary values here, in this case:
54
+
Nous avons également besoin d'une propriété pour calculer les valeurs intermédiaires lors de la transition, dans notre cas :
55
55
56
56
```css
57
57
.box {
@@ -62,7 +62,7 @@ We'd also need a style property that will transition the intermediary values her
62
62
<pdata-height="450"data-theme-id="5162"data-slug-hash="983220ed949ac670dff96bdcaf9d3338"data-default-tab="result"data-user="sdras"data-embed-version="2"data-pen-title="Custom Scroll Directive- CSS Transition"class="codepen">See the Pen <ahref="https://codepen.io/sdras/pen/983220ed949ac670dff96bdcaf9d3338/">Custom Scroll Directive- CSS Transition</a> by Sarah Drasner (<ahref="https://codepen.io/sdras">@sdras</a>) on <ahref="https://codepen.io">CodePen</a>.</p>
Or, with GreenSock(GSAP) or any other JavaScript animation library, the code becomes even more simple:
65
+
Ou, avec GreenSock(GSAP) ou toute autre librairie d'animation JavaScript, le code devient encore plus simple:
66
66
67
67
```js
68
68
Vue.directive('scroll', {
@@ -94,28 +94,28 @@ new Vue({
94
94
})
95
95
```
96
96
97
-
Though we would remove the previous CSS transition from this implementation because it's now handled with JavaScript.
97
+
Nous devons retirer la transition CSS de l'exemple précédent puisque dans cette implémentation, tout est calculé directement avec JavaScript.
98
98
99
-
## The Benefit of Using Custom Directives
99
+
## Le bénéfice de l'utilisation des directives personnalisées
100
100
101
-
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.
101
+
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.
102
102
103
-
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.
103
+
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.
104
104
105
-
## Real-World Example: Using a Custom Scroll Directive for Cascading Animations
105
+
## Exemple concret : Utiliser une directive de défilement personnalisée pour animer en cascade
106
106
107
-
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.
107
+
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.
108
108
109
-
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.
109
+
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.
110
110
111
-
**This example is better viewed in the [full screen version](https://s.codepen.io/sdras/debug/078c19f5b3ed7f7d28584da450296cd0).**
111
+
**Cet exemple est plus visuel [en plein écran](https://s.codepen.io/sdras/debug/078c19f5b3ed7f7d28584da450296cd0).**
112
112
113
113
<pdata-height="500"data-theme-id="5162"data-slug-hash="c8c55e3e0bba997350551dd747119100"data-default-tab="result"data-user="sdras"data-embed-version="2"data-pen-title="Scrolling Example- Using Custom Directives in Vue"class="codepen">See the Pen <ahref="https://codepen.io/sdras/pen/c8c55e3e0bba997350551dd747119100/">Scrolling Example- Using Custom Directives in Vue</a> by Sarah Drasner (<ahref="https://codepen.io/sdras">@sdras</a>) on <ahref="https://codepen.io">CodePen</a>.</p>
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.
116
+
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 `<path>` du SVG. Réutilisons ces deux animation pour créer une directive personnalisée pour chaqu'un des cas. Les arguments qui seront transmis vont nous aider à garder l'ensemble simple et réutilisable.
117
117
118
-
To show how we do this, we'll take a look at the morphing shape example, where we'll need to state the start and finish, as well as pass in a path value that we'll create a morph to. These arguments are each defined as `binding.value.foo`:
118
+
Pour analyser l'exemple de l'animation « morphing », nous aurons besoin d'indiquer ou l'animation commence et termine ainsi que la valeur du `<path>` qui va permettre le calcul du morphing. Ces arguments sont définis via `binding.value.foo`:
119
119
120
120
```js
121
121
Vue.directive('clipscroll', {
@@ -138,7 +138,7 @@ Vue.directive('clipscroll', {
138
138
})
139
139
```
140
140
141
-
We can then use this animation in our template, in this case we're attaching the directive to the `clipPath` element, and pass all of our arguments to the directives in an object.
141
+
Nous pouvons alors utiliser cette animation directement dans le `<template>`, en attachant la directive à l'élément `<path>` tout en transmettant les arguments de la directive dans un `Object`
142
142
143
143
```html
144
144
<clipPathid="clip-path">
@@ -150,8 +150,8 @@ We can then use this animation in our template, in this case we're attaching the
150
150
</clipPath>
151
151
```
152
152
153
-
## Alternative Patterns
153
+
## Alternative
154
154
155
-
Custom directives are extremely useful, but you may find some situations where you need something very specific that already exists in scrolling libraries that you don't wish to rebuild from scratch yourself.
155
+
Les directives personnalisées sont extrêmement utiles, mais vous pouvez trouver des situations dans lesquelles vous aurez besoin de quelque chose de très spécifique, qui existe déjà dans des librairies de défilement et que vous ne souhaitez pas réécrire totalement vous-même.
156
156
157
-
[Scrollmagic](http://scrollmagic.io/)has a very rich ecosystem of offerings to work with, as well as good documentation and demos to explore. This includes, but is not limited to things like [parallax](http://scrollmagic.io/examples/advanced/parallax_scrolling.html), [cascading pinning](http://scrollmagic.io/examples/expert/cascading_pins.html), [section wipes](http://scrollmagic.io/examples/basic/section_wipes_natural.html), and[responsive duration](http://scrollmagic.io/examples/basic/responsive_duration.html).
157
+
[Scrollmagic](http://scrollmagic.io/)est doté d'un écosysteme très riche, une très bonne documentation ainsi que des démos à explorer. Cela inclus de façon non exhaustive, des cas comme [l'effet parallax](http://scrollmagic.io/examples/advanced/parallax_scrolling.html), [Épingler en cascade](http://scrollmagic.io/examples/expert/cascading_pins.html), [Recouvrement de section](http://scrollmagic.io/examples/basic/section_wipes_natural.html), et[responsive duration](http://scrollmagic.io/examples/basic/responsive_duration.html).
0 commit comments