Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
step-12 animations
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jan 20, 2016
1 parent 3a69cd6 commit 97a4aa5
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 8 deletions.
97 changes: 97 additions & 0 deletions app/css/animations.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* animations css stylesheet
*/

/* animate ngRepeat in phone listing */

.phone-listing.ng-enter,
.phone-listing.ng-leave,
.phone-listing.ng-move {
-webkit-transition: 0.5s linear all;
-moz-transition: 0.5s linear all;
-o-transition: 0.5s linear all;
transition: 0.5s linear all;
}

.phone-listing.ng-enter,
.phone-listing.ng-move {
opacity: 0;
height: 0;
overflow: hidden;
}

.phone-listing.ng-move.ng-move-active,
.phone-listing.ng-enter.ng-enter-active {
opacity: 1;
height: 120px;
}

.phone-listing.ng-leave {
opacity: 1;
overflow: hidden;
}

.phone-listing.ng-leave.ng-leave-active {
opacity: 0;
height: 0;
padding-top: 0;
padding-bottom: 0;
}

/* cross fading between routes with ngView */

.view-container {
position: relative;
}

.view-frame.ng-enter,
.view-frame.ng-leave {
background: white;
position: absolute;
top: 0;
left: 0;
right: 0;
}

.view-frame.ng-enter {
-webkit-animation: 0.5s fade-in;
-moz-animation: 0.5s fade-in;
-o-animation: 0.5s fade-in;
animation: 0.5s fade-in;
z-index: 100;
}

.view-frame.ng-leave {
-webkit-animation: 0.5s fade-out;
-moz-animation: 0.5s fade-out;
-o-animation: 0.5s fade-out;
animation: 0.5s fade-out;
z-index: 99;
}

@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
@-moz-keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
@-webkit-keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}

@keyframes fade-out {
from { opacity: 1; }
to { opacity: 0; }
}
@-moz-keyframes fade-out {
from { opacity: 1; }
to { opacity: 0; }
}
@-webkit-keyframes fade-out {
from { opacity: 1; }
to { opacity: 0; }
}

17 changes: 16 additions & 1 deletion app/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ body {
padding-top: 20px;
}


.phone-images {
background-color: white;
width: 450px;
height: 450px;
overflow: hidden;
position: relative;
float: left;
}

.phones {
list-style: none;
}
Expand All @@ -25,15 +35,20 @@ body {
/** Detail View **/
img.phone {
float: left;
border: 1px solid black;
margin-right: 3em;
margin-bottom: 2em;
background-color: white;
padding: 2em;
height: 400px;
width: 400px;
display: none;
}

img.phone:first-child {
display: block;
}


ul.phone-thumbs {
margin: 0;
list-style: none;
Expand Down
9 changes: 8 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
<title>Google Phone Gallery</title>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/animations.css">

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="js/app.js"></script>
<script src="js/animations.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/services.js"></script>
</head>
<body>

<div ng-view></div>
<div class="view-container">
<div ng-view class="view-frame"></div>
</div>

</body>
</html>
52 changes: 52 additions & 0 deletions app/js/animations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var phonecatAnimations = angular.module('phonecatAnimations', ['ngAnimate']);

phonecatAnimations.animation('.phone', function() {

var animateUp = function(element, className, done) {
if(className != 'active') {
return;
}
element.css({
position: 'absolute',
top: 500,
left: 0,
display: 'block'
});

jQuery(element).animate({
top: 0
}, done);

return function(cancel) {
if(cancel) {
element.stop();
}
};
}

var animateDown = function(element, className, done) {
if(className != 'active') {
return;
}
element.css({
position: 'absolute',
left: 0,
top: 0
});

jQuery(element).animate({
top: -500
}, done);

return function(cancel) {
if(cancel) {
element.stop();
}
};
}

return {
addClass: animateUp,
removeClass: animateDown
};
});
2 changes: 2 additions & 0 deletions app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatAnimations',

'phonecatControllers',
'phonecatFilters',
'phonecatServices'
Expand Down
7 changes: 6 additions & 1 deletion app/partials/phone-detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<img ng-src="{{mainImageUrl}}" class="phone">
<div class="phone-images">
<img ng-src="{{img}}"
class="phone"
ng-repeat="img in phone.images"
ng-class="{active: mainImageUrl==img}">
</div>

<h1>{{phone.name}}</h1>

Expand Down
3 changes: 2 additions & 1 deletion app/partials/phone-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<!--Body content-->

<ul class="phones">
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp" class="thumbnail">
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp"
class="thumbnail phone-listing">
<a href="#/phones/{{phone.id}}" class="thumb"><img ng-src="{{phone.imageUrl}}" alt="{{phone.name}}"></a>
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
<p>{{phone.snippet}}</p>
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"jquery": "~2.1.1",
"bootstrap": "~3.1.1",
"angular-route": "1.4.x",
"angular-resource": "1.4.x"
"angular-resource": "1.4.x",
"angular-animate": "1.4.x"
}
}
6 changes: 3 additions & 3 deletions test/e2e/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ describe('PhoneCat App', function() {


it('should display the first phone image as the main phone image', function() {
expect(element(by.css('img.phone')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
});


it('should swap main image if a thumbnail image is clicked on', function() {
element(by.css('.phone-thumbs li:nth-child(3) img')).click();
expect(element(by.css('img.phone')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);

element(by.css('.phone-thumbs li:nth-child(1) img')).click();
expect(element(by.css('img.phone')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
});
});
});
1 change: 1 addition & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function(config){
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-animate/angular-animate.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
Expand Down

0 comments on commit 97a4aa5

Please sign in to comment.