forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransitions-setup-initial-transition.diff
54 lines (50 loc) · 1.78 KB
/
transitions-setup-initial-transition.diff
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
diff --git a/assets/styles/app.css b/assets/styles/app.css
index 6d01054..6de3abb 100644
--- a/assets/styles/app.css
+++ b/assets/styles/app.css
@@ -4,6 +4,10 @@
body {
font-family: 'Montserrat', sans-serif;
+ transition: opacity 1000ms;
+}
+body.turbo-loading {
+ opacity: .2;
}
/*
[data-turbo-preview] body {
diff --git a/assets/turbo/turbo-helper.js b/assets/turbo/turbo-helper.js
index dcefc45..a7083a9 100644
--- a/assets/turbo/turbo-helper.js
+++ b/assets/turbo/turbo-helper.js
@@ -10,6 +10,22 @@ const TurboHelper = class {
document.addEventListener('turbo:render', () => {
this.initializeWeatherWidget();
});
+
+ document.addEventListener('turbo:visit', () => {
+ // fade out the old body
+ document.body.classList.add('turbo-loading');
+ });
+ document.addEventListener('turbo:before-render', (event) => {
+ // when we are *about* to render, start us faded out
+ event.detail.newBody.classList.add('turbo-loading');
+ });
+ document.addEventListener('turbo:render', () => {
+ // after rendering, we first allow the turbo-loading class to set the low opacity
+ // THEN, one frame later, we remove the turbo-loading class, which allows the fade in
+ requestAnimationFrame(() => {
+ document.body.classList.remove('turbo-loading');
+ });
+ });
}
closeModal() {
diff --git a/public/index.php b/public/index.php
index 9982c21..52a2316 100644
--- a/public/index.php
+++ b/public/index.php
@@ -3,6 +3,7 @@
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
+sleep(1);
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);