transitioncancel-001.html (2361B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>CSS Transitions Test: display:none causes transitioncancel</title> 6 <meta name="timeout" content="long"> 7 <link rel="author" title="Chris Rebert" href="http://chrisrebert.com"> 8 <link rel="help" href="https://drafts.csswg.org/css-transitions-2/#event-dispatch"> 9 <link rel="help" href="https://lists.w3.org/Archives/Public/www-style/2015Apr/0405.html" data-section-title="AnimationEnd events and display: none"> 10 <meta name="flags" content="dom"> 11 <meta name="assert" content="Making an element display:none; while it has a transition in progress should fire a transitioncancel event."> 12 <script src="/resources/testharness.js"></script> 13 <script src="/resources/testharnessreport.js"></script> 14 <style> 15 #a { 16 height: 100px; 17 width: 100px; 18 transition: background-color 2s; 19 } 20 .red { 21 background-color: red; 22 } 23 .blue { 24 background-color: blue; 25 } 26 .hidden { 27 display: none !important; 28 } 29 </style> 30 <script> 31 async_test(function (t) { 32 window.addEventListener('load', function () { 33 var div = document.getElementById('a'); 34 var canceled = false; 35 var after = false; 36 div.addEventListener('transitioncancel', function () { 37 canceled = true; 38 t.step(function () { 39 assert_true(true, "transitioncancel event did fire"); 40 }); 41 }, false); 42 43 div.className = 'blue';// initiate transition 44 window.setTimeout(function () { 45 t.step(function () { 46 assert_false(canceled, "transitioncancel did not fire before hiding callback ran"); 47 assert_false(after, "hiding callback ran before the end of the test"); 48 }); 49 div.className += ' hidden';// force display:none during the transition 50 }, 1000);// halfway into the transition 51 window.setTimeout(function () { 52 after = true; 53 t.step(function () { 54 assert_true(canceled, "transitioncancel event did fire"); 55 t.done(); 56 }); 57 }, 2100);// after the transition would have ended 58 }, false); 59 }, "transitioncancel should be fired if the element is made display:none during the transition"); 60 </script> 61 </head> 62 <body> 63 <div id="a" class="red"></div> 64 </body> 65 </html>