Skip to content

Commit 305696c

Browse files
docs(tutorial/step-12): add info about app.css changes
Closes angular/angular-phonecat#145
1 parent ff03d7b commit 305696c

File tree

1 file changed

+67
-27
lines changed

1 file changed

+67
-27
lines changed

docs/content/tutorial/step_12.ngdoc

+67-27
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,22 @@ __`app/css/animations.css`.__
323323
/* don't forget about the vendor-prefixes! */
324324
```
325325

326-
Nothing crazy here! Just a simple fade in and fade out effect between pages. The only out of the ordinary thing
327-
here is that we're using absolute positioning to position the next page (identified via `ng-enter`) on top of the
328-
previous page (the one that has the `ng-leave` class) while performing a cross fade animation in between. So
329-
as the previous page is just about to be removed, it fades out while the new page fades in right on top of it.
330-
Once the leave animation is over then element is removed and once the enter animation is complete then the
331-
`ng-enter` and `ng-enter-active` CSS classes are removed from the element rendering it to be position itself
332-
with its default CSS code (so no more absolute positioning once the animation is over). This works fluidly so
333-
that pages flow naturally between route changes without anything jumping around.
334-
335-
The CSS classes applied (the start and end classes) are much the same as with `ng-repeat`. Each time a new page is
336-
loaded the ng-view directive will create a copy of itself, download the template and append the contents. This
337-
ensures that all views are contained within a single HTML element which allows for easy animation control.
326+
Nothing crazy here! Just a simple fade in and fade out effect between pages. The only out of the
327+
ordinary thing here is that we're using absolute positioning to position the next page (identified
328+
via `ng-enter`) on top of the previous page (the one that has the `ng-leave` class) while performing
329+
a cross fade animation in between. So as the previous page is just about to be removed, it fades out
330+
while the new page fades in right on top of it.
331+
332+
Once the leave animation is over then element is removed and once the enter animation is complete
333+
then the `ng-enter` and `ng-enter-active` CSS classes are removed from the element rendering it to
334+
be position itself with its default CSS code (so no more absolute positioning once the animation is
335+
over). This works fluidly so that pages flow naturally between route changes without anything
336+
jumping around.
337+
338+
The CSS classes applied (the start and end classes) are much the same as with `ng-repeat`. Each time
339+
a new page is loaded the ng-view directive will create a copy of itself, download the template and
340+
append the contents. This ensures that all views are contained within a single HTML element which
341+
allows for easy animation control.
338342

339343
For more on CSS animations, see the
340344
[Web Platform documentation](http://docs.webplatform.org/wiki/css/properties/animations).
@@ -346,14 +350,14 @@ Let's add another animation to our application. Switching to our `phone-detail.h
346350
we see that we have a nice thumbnail swapper. By clicking on the thumbnails listed on the page,
347351
the profile phone image changes. But how can we change this around to add animations?
348352

349-
Let's think about it first. Basically, when you click on a thumbnail image, you're changing the state of the profile image to reflect the newly
350-
selected thumbnail image.
353+
Let's think about it first. Basically, when you click on a thumbnail image, you're changing the
354+
state of the profile image to reflect the newly selected thumbnail image.
351355
The best way to specify state changes within HTML is to use classes.
352-
Much like before, how we used a CSS class to specify
353-
an animation, this time the animation will occur whenever the CSS class itself changes.
356+
Much like before, how we used a CSS class to specify an animation, this time the animation will
357+
occur whenever the CSS class itself changes.
354358

355-
Whenever a new phone thumbnail is selected, the state changes and the `.active` CSS class is added to the matching
356-
profile image and the animation plays.
359+
Whenever a new phone thumbnail is selected, the state changes and the `.active` CSS class is added
360+
to the matching profile image and the animation plays.
357361

358362
Let's get started and tweak our HTML code on the `phone-detail.html` page first:
359363

@@ -379,18 +383,54 @@ __`app/partials/phone-detail.html`.__
379383
</ul>
380384
```
381385

382-
Just like with the thumbnails, we're using a repeater to display **all** the profile images as a list, however we're
383-
not animating any repeat-related animations. Instead, we're keeping our eye on the ng-class directive since whenever
384-
the `active` class is true then it will be applied to the element and will render as visible. Otherwise, the profile image
385-
is hidden. In our case, there is always one element that has the active class, and, therefore, there will always
386-
be one phone profile image visible on screen at all times.
386+
Just like with the thumbnails, we're using a repeater to display **all** the profile images as a
387+
list, however we're not animating any repeat-related animations. Instead, we're keeping our eye on
388+
the ng-class directive since whenever the `active` class is true then it will be applied to the
389+
element and will render as visible. Otherwise, the profile image is hidden. In our case, there is
390+
always one element that has the active class, and, therefore, there will always be one phone profile
391+
image visible on screen at all times.
392+
393+
When the active class is added to the element, the `active-add` and the `active-add-active` classes
394+
are added just before to signal AngularJS to fire off an animation. When removed, the
395+
`active-remove` and the `active-remove-active` classes are applied to the element which in turn
396+
trigger another animation.
397+
398+
To ensure that the phone images are displayed correctly when the page is first loaded we also tweak
399+
the detail page CSS styles:
400+
401+
__`app/css/app.css`__
402+
```css
403+
.phone-images {
404+
background-color: white;
405+
width: 450px;
406+
height: 450px;
407+
overflow: hidden;
408+
position: relative;
409+
float: left;
410+
}
411+
412+
...
413+
414+
img.phone {
415+
float: left;
416+
margin-right: 3em;
417+
margin-bottom: 2em;
418+
background-color: white;
419+
padding: 2em;
420+
height: 400px;
421+
width: 400px;
422+
display: none;
423+
}
424+
425+
img.phone:first-child {
426+
display: block;
427+
}
428+
```
387429

388-
When the active class is added to the element, the `active-add` and the `active-add-active` classes are added just before
389-
to signal AngularJS to fire off an animation. When removed, the `active-remove` and the `active-remove-active` classes
390-
are applied to the element which in turn trigger another animation.
391430

392431
You may be thinking that we're just going to create another CSS-enabled animation.
393-
Although we could do that, let's take the opportunity to learn how to create JavaScript-enabled animations with the `animation()` module method.
432+
Although we could do that, let's take the opportunity to learn how to create JavaScript-enabled
433+
animations with the `animation()` module method.
394434

395435
__`app/js/animations.js`.__
396436

0 commit comments

Comments
 (0)