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
**Highway** is a *modern*, *flexible* and *lightweight* library that will let you create **AJAX navigations** with beautiful **transitions** on your websites. It's been a while we were trying to build this kind of library to fits our needs at [**Dogstudio**](https://www.dogstudio.co) and that hopefully will fit yours now we're releasing it!
@@ -39,7 +38,9 @@ or *require* it if you prefer:
39
38
```javascript
40
39
constHighway=require('@dogstudio/highway');
41
40
```
42
-
Now **Highway** is available you need to create an instance of `Highway.Core` and give it your [**renderers**]() and [**transitions**]().
41
+
42
+
Now **Highway** is available you need to create an instance of `Highway.Core` and give it your [**renderers**](https://github.com/Dogstudio/highway#renderers) and [**transitions**](https://github.com/Dogstudio/highway#transitions).
43
+
43
44
```javascript
44
45
constH=newHighway.Core({
45
46
renderers: {
@@ -91,6 +92,9 @@ import Highway from '@dogstudio/highway';
91
92
classHomeextendsHighway.renderer {
92
93
[...]
93
94
}
95
+
96
+
// Don`t forget to export your renderer
97
+
exportdefaultHome;
94
98
```
95
99
Besides the required methods from **Highway** present in the `Highway.renderer` you have access to **optional** ones that are called all along the process of the navigation. Here is the list of these **optional** methods:
96
100
@@ -114,7 +118,9 @@ class Home extends Highway.renderer {
114
118
// Don`t forget to export your renderer
115
119
exportdefaultHome;
116
120
```
117
-
Now your custom renderer is created you need to add it to the renderers list of `Highway.Core`... Remember the name you gave to you `router-view`, it's now time to use it to relate your renderer in Javascript to you `router-view` in HTML.
121
+
122
+
Now your custom renderer is created you need to add it to the renderers list of `Highway.Core`...
123
+
Remember the name you gave to you `router-view`, it's now time to relate it to your renderer.
118
124
119
125
```javascript
120
126
// Import Renderers
@@ -131,6 +137,73 @@ const H = new Highway.Core({
131
137
});
132
138
```
133
139
140
+
## Transitions
141
+
142
+
OK so now you have your custom renderers but you are sad because there are no transitions between your pages...
143
+
Don't be afraid, let's now see how to create our first transition!
144
+
145
+
Transitions in **Highway** are really simple, these are objects with two methods:
146
+
147
+
-`in`: The `in` method should contain the transition to show a `[router-view]`.
148
+
-`out`: The `out` method should contain the transition to hide a `[router-view]`.
149
+
150
+
Each one get two parameters you can call how you want but here are good defaults:
151
+
152
+
-`view`: The `[router-view]` you will show/hide.
153
+
-`done`: The callback method **you have to** call once the `in` and `out` transitions are over.
154
+
155
+
**transition.js**
156
+
```javascript
157
+
constTransition= {
158
+
in: (view, done) => {
159
+
// [...]
160
+
},
161
+
out: (view, done) => {
162
+
// [...]
163
+
}
164
+
};
165
+
166
+
// Don't forget to export your transition
167
+
exportdefaultTransition;
168
+
```
169
+
170
+
Now your transition is created you need to add it to the transitions list of `Highway.Core`...
171
+
Remember the name you gave to you `router-view`, it's now time to relate it to your transition.
172
+
173
+
```javascript
174
+
// Import Renderers
175
+
importHomefrom'path/to/home.js';
176
+
177
+
// Import Transitions
178
+
importTransitionfrom'path/to/transition.js';
179
+
180
+
// Relate you transition to your [router-view] name
181
+
constH=newHighway.Core({
182
+
renderers: {
183
+
home: Home
184
+
},
185
+
transitions: {
186
+
home: Transition
187
+
}
188
+
});
189
+
```
190
+
191
+
Last but not least, you might want to use the same transition for all the pages across your website. This is possible by adding a `default` key to your transitions list. When you do so for each page **Highway** will look for a transition in the list related to your `router-view` name and fallback to the `default` one if none is found.
192
+
193
+
```javascript
194
+
// [...]
195
+
constH=newHighway.Core({
196
+
renderers: {
197
+
home: Home
198
+
},
199
+
transitions: {
200
+
default: Transition
201
+
}
202
+
});
203
+
```
204
+
205
+
Check out the [**examples**](https://github.com/Dogstudio/highway#examples) for more details about transitions in **Highway**.
0 commit comments