1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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>
|