-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlideView.js
120 lines (95 loc) · 3.43 KB
/
SlideView.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*** SlideView.js ***/
define(function(require, exports, module) {
var View = require('famous/core/View');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var StateModifier = require('famous/modifiers/StateModifier');
var ImageSurface = require('famous/surfaces/ImageSurface');
var Transitionable = require('famous/transitions/Transitionable');
var SpringTransition = require('famous/transitions/SpringTransition');
Transitionable.registerMethod('spring', SpringTransition);
var SlideData = require('../data/SlideData');
function SlideView() {
View.apply(this, arguments);
this.rootModifier = new StateModifier({
size: this.options.size
});
this.mainNode = this.add(this.rootModifier);
_createBackground.call(this);
_createFilm.call(this);
_createPhoto.call(this);
}
SlideView.prototype = Object.create(View.prototype);
SlideView.prototype.constructor = SlideView;
SlideView.DEFAULT_OPTIONS = {
size: [400, 450],
filmBorder: 15,
photoBorder: 3,
photoUrl: SlideData.defaultImage,
angle: -0.5
};
function _createBackground() {
var background = new Surface({
properties: {
backgroundColor: '#FFFFF5',
boxShadow: '0 10px 20px -5px rgba(0, 0, 0, 0.5)',
cursor: 'pointer'
}
});
this.mainNode.add(background);
background.on('click', function() {
this._eventOutput.emit('click');
}.bind(this));
}
function _createFilm() {
this.options.filmSize = this.options.size[0] - 2 * this.options.filmBorder;
var film = new Surface({
size: [this.options.filmSize, this.options.filmSize],
properties: {
backgroundColor: '#222',
zIndex: 1,
pointerEvents: 'none'
}
});
var filmModifier = new StateModifier({
origin: [0.5, 0],
align: [0.5, 0],
transform: Transform.translate(0, this.options.filmBorder, 0.05)
});
this.mainNode.add(filmModifier).add(film);
}
function _createPhoto() {
var size = this.options.filmSize - 2 * this.options.photoBorder;
var photo = new ImageSurface({
size: [size, size],
content: this.options.photoUrl,
properties: {
zIndex: 2,
pointerEvents: 'none'
}
});
this.photoModifier = new StateModifier({
origin: [0.5, 0],
align: [0.5, 0],
transform: Transform.translate(0, this.options.filmBorder + this.options.photoBorder, 0.1),
opacity: 0.01
});
this.mainNode.add(this.photoModifier).add(photo);
}
SlideView.prototype.fadeIn = function() {
this.photoModifier.setOpacity(1, { duration: 1500, curve: 'easeIn' });
this.shake();
};
SlideView.prototype.shake = function() {
this.rootModifier.halt();
this.rootModifier.setTransform(
Transform.rotateX(this.options.angle),
{ duration: 200, curve: 'easeOut' }
);
this.rootModifier.setTransform(
Transform.identity,
{ method: 'spring', period: 600, dampingRatio: 0.15 }
);
};
module.exports = SlideView;
});