diff options
Diffstat (limited to 'files/fr/web/api/htmlelement/transitionend_event/index.md')
-rw-r--r-- | files/fr/web/api/htmlelement/transitionend_event/index.md | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/files/fr/web/api/htmlelement/transitionend_event/index.md b/files/fr/web/api/htmlelement/transitionend_event/index.md new file mode 100644 index 0000000000..a780a3023b --- /dev/null +++ b/files/fr/web/api/htmlelement/transitionend_event/index.md @@ -0,0 +1,191 @@ +--- +title: transitionend +slug: Web/API/HTMLElement/transitionend_event +tags: + - DOM + - Event + - TransitionEvent + - Transitions CSS + - Transitions CSS3 + - transitionend +translation_of: Web/API/HTMLElement/transitionend_event +original_slug: Web/Events/transitionend +--- +<div>{{APIRef}}</div> + +<p>L'événement <strong><code>transitionend</code></strong> est déclenché lorsqu'une <a href="/en-US/docs/CSS/Using_CSS_transitions">transition CSS</a> est terminée. Dans le cas où une transition est supprimée avant la fin, par exemple si {{cssxref ("transition-property")}} est supprimé ou {{cssxref ("display")}} est défini sur <code>none</code>, alors l'événement ne pourra pas être généré.</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">Bulles</th> + <td>Oui</td> + </tr> + <tr> + <th scope="row">Annulable</th> + <td>Oui</td> + </tr> + <tr> + <th scope="row">Interface</th> + <td>{{domxref("TransitionEvent")}}</td> + </tr> + <tr> + <th scope="row">Propriété de gestionnaire d'événements</th> + <td>{{domxref("GlobalEventHandlers/ontransitionend", "ontransitionend")}}</td> + </tr> + </tbody> +</table> + +<p>L'événement <code>transitionend</code> est déclenché dans les deux sens - à la fin de la transition vers l'état de transition et lorsqu'il revient complètement à l'état par défaut ou sans transition. S'il n'y a pas de délai ou de durée de transition, si les deux sont 0 ou qu'aucun n'est déclaré, il n'y a pas de transition et aucun des événements de transition n'est déclenché. Si l'événement <code>transitioncancel</code> est déclenché, l'événement <code>transitionend</code> ne se déclenchera pas.</p> + +<h2 id="Propriétés">Propriétés</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Propriétés</th> + <th scope="col">Type</th> + <th scope="col">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>target</code> {{readonlyInline}}</td> + <td>{{domxref("EventTarget")}}</td> + <td>The event target (the topmost target in the DOM tree).</td> + </tr> + <tr> + <td><code>type</code> {{readonlyInline}}</td> + <td>{{domxref("DOMString")}}</td> + <td>The type of event.</td> + </tr> + <tr> + <td><code>bubbles</code> {{readonlyInline}}</td> + <td>{{jsxref("Boolean")}}</td> + <td>Whether the event normally bubbles or not.</td> + </tr> + <tr> + <td><code>cancelable</code> {{readonlyInline}}</td> + <td>{{jsxref("Boolean")}}</td> + <td>Whether the event is cancellable or not.</td> + </tr> + <tr> + <td><code>propertyName</code> {{readonlyInline}}</td> + <td>{{domxref("DOMString")}}</td> + <td>The name of the CSS property associated with the transition.</td> + </tr> + <tr> + <td><code>elapsedTime</code> {{readonlyInline}}</td> + <td>Float</td> + <td>The amount of time the transition has been running, in seconds, as of the time the event was generated. This value is not affected by the value of <code>transition-delay</code>.</td> + </tr> + <tr> + <td><code>pseudoElement</code> {{readonlyInline}}</td> + <td>{{domxref("DOMString")}}</td> + <td>The name (beginning with two colons) of the CSS pseudo-element on which the transition occured (in which case the target of the event is that pseudo-element's corresponding element), or the empty string if the transition occurred on an element (which means the target of the event is that element).</td> + </tr> + </tbody> +</table> + +<h2 id="Examples">Examples</h2> + +<p>This code gets an element that has a transition defined and adds a listener to the <code>transitionend</code> event:</p> + +<pre class="brush: js">const transition = document.querySelector('.transition'); + +transition.addEventListener('transitionend', () => { + console.log('Transition ended'); +});</pre> + +<p>The same, but using the {{domxref("GlobalEventHandlers/ontransitionend", "ontransitionend")}}:</p> + +<pre class="brush: js">const transition = document.querySelector('.transition'); + +transition.ontransitionend = () => { + console.log('Transition ended'); +};</pre> + +<h3 id="Live_example">Live example</h3> + +<p>In the following example, we have a simple {{htmlelement("div")}} element, styled with a transition that includes a delay:</p> + +<pre class="brush: html"><div class="transition">Hover over me</div> +<div class="message"></div></pre> + +<pre class="brush: css">.transition { + width: 100px; + height: 100px; + background: rgba(255,0,0,1); + transition-property: transform background; + transition-duration: 2s; + transition-delay: 1s; +} + +.transition:hover { + transform: rotate(90deg); + background: rgba(255,0,0,0); +}</pre> + +<p>To this, we'll add some JavaScript to indicate that the <code><a href="/en-US/docs/Web/API/HTMLElement/transitionstart_event">transitionstart</a></code>, <code><a href="/en-US/docs/Web/API/HTMLElement/transitionrun_event">transitionrun</a></code>, <code><a href="/en-US/docs/Web/API/Window/transitioncancel_event">transitioncancel</a></code> and <code>transitionend</code> events fire. In this example, to cancel the transition, stop hovering over the transitioning box before the transition ends. For the transition end event to fire, stay hovered over the transition until the transition ends.</p> + +<pre class="brush: js">const message = document.querySelector('.message'); +const el = document.querySelector('.transition'); + +el.addEventListener('transitionrun', function() { + message.textContent = 'transitionrun fired'; +}); + +el.addEventListener('transitionstart', function() { + message.textContent = 'transitionstart fired'; +}); + +el.addEventListener('transitioncancel', function() { + message.textContent = 'transitioncancel fired'; +}); + +el.addEventListener('transitionend', function() { + message.textContent = 'transitionend fired'; +}); +</pre> + +<p>{{ EmbedLiveSample('Live_example', '100%', '150px') }}</p> + +<p>The <code>transitionend</code> event is fired in both directions: when the box finishes turning and the opacity hits 0 or 1, depending on the direction.</p> + +<p>If there is no transition delay or duration, if both are 0s or neither is declared, there is no transition, and none of the transition events are fired.</p> + +<p>If the <code>transitioncancel</code> event is fired, the <code>transitionend</code> event will not fire.</p> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Spécification</th> + <th scope="col">Statut</th> + <th scope="col">Commentaire</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS3 Transitions", "#transitionend", "transitionend")}}</td> + <td>{{Spec2('CSS3 Transitions')}}</td> + <td>Définition initiale.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<p>{{Compat("api.HTMLElement.transitionend_event")}}</p> + +<h2 id="Voir_également">Voir également</h2> + +<ul> + <li>Le gestionnaire d'événements {{domxref("GlobalEventHandlers.ontransitionend")}}</li> + <li>L'interface {{domxref("TransitionEvent")}}</li> + <li>Propriétés CSS : {{cssxref("transition")}}, {{cssxref("transition-delay")}}, {{cssxref("transition-duration")}}, {{cssxref("transition-property")}}, {{cssxref("transition-timing-function")}}</li> + <li>Événements liés: {{domxref("HTMLElement/transitionrun_event", "transitionrun")}}, {{domxref("HTMLElement/transitionstart_event", "transitionstart")}}, {{domxref("HTMLElement/transitioncancel_event", "transitioncancel")}}</li> + <li>Cet événement sur {{domxref("Document")}} cible : {{domxref("Document/transitionend_event", "transitionend")}}</li> + <li>Cet événement sur {{domxref("Window")}} cible : {{domxref("Window/transitionend_event", "transitionend")}}</li> +</ul> |