Ajax Loader
×
HTML
<section id="timeline">
1
<section id="timeline">
2
 
3
    <div class="timeline">
4
        <canvas id="cvs3"></canvas>
5
        <article>
6
            <h2>Education</h2>          
7
            <figure>
8
                <figcaption>Lorem</figcaption>
9
                <h6>2011 - NOW</h6>
10
                <p>
11
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero. Ut ut libero in nibh convallis sollicitudin. Maecenas ante erat, lacinia commodo pretium vel, ultricies eget nibh. Duis et felis lectus. Donec orci libero, auctor eget sodales at, euismod venenatis nibh.
12
                </p>
13
            </figure>
14
            <figure>
15
                <figcaption>ipsum</figcaption>
16
                <h6>2013</h6>
17
                <p>
18
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
19
                </p>
20
            </figure>
21
            <figure>
22
                <figcaption>consectetur</figcaption>
23
                <h6>2007 - 2010</h6>
24
                <p>
25
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
26
                </p>
27
            </figure>
28
            <figure>
29
                <figcaption>sit amet</figcaption>
30
                <h6>2009</h6>
31
                <p>                    
32
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
33
                </p>
34
            </figure>
35
        </article>
36
 
37
        <article>
38
            <h2>Work</h2>
39
            <figure>
40
                <figcaption>ornare</figcaption>
41
                <h6>2012 - 06.2013</h6>
42
                <p>
43
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
44
            </figure>
45
            <figure>
46
                <figcaption>libero</figcaption>
47
                <h6>2010 - 2011</h6>
48
                <p>
49
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
50
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
51
                </p>
52
            </figure>
53
            <figure>
54
                <figcaption>adipiscing</figcaption>
55
                <h6>2010</h6>
56
                <p>
57
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam et ipsum pulvinar, blandit neque in, ornare libero.
58
                </p>
59
            </figure>
60
        </article>
61
        <br style="clear:both" />
62
    </div>
63
 
64
</section>
65
 
66
 
67
<script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
 
CSS
@import url(http://fonts.googleapis.com/css?family=Lato:400|Raleway:400);
1
@import url(http://fonts.googleapis.com/css?family=Lato:400|Raleway:400);
2
* {
3
  margin: 0;
4
  padding: 0;
5
  box-sizing: border-box;
6
}
7
body,
8
html {
9
  color: #2C2C2C;
10
  min-width: 600px;
11
  height: 100%;
12
  background: white;
13
  font: 400 1em 'Lato';
14
  -webkit-font-smoothing: antialiased;
15
}
16
#timeline {
17
  padding-top: 5%;
18
}
19
.timeline {
20
  height: 100%;
21
  position: relative;
22
}
23
.timeline canvas {
24
  position: absolute;
25
  width: 100%;
26
  height: 100%;
27
  left: 0;
28
  top: 0;
29
}
30
.timeline figcaption {
31
  font: 900 190% 'Lato';
32
  text-transform: uppercase;
33
  -webkit-text-stroke: .25px;
34
}
35
.timeline h2 {
36
  font: 400 400% 'Raleway';
37
  padding-bottom: 100px;
38
  color: #b2cde9;
39
}
40
.timeline h6 {
41
  color: #0090F5;
42
  font: 400 80% Tahoma;
43
}
44
.timeline p,
45
.timeline ol {
46
  font: 400 95% 'Raleway';
47
  padding: 3px 0 20px 0;
48
  color: #575757;
49
  text-align: justify;
50
  width: 70%;
51
}
52
.timeline ol {
53
  list-style: disc;
54
  margin-top: -20px;
55
  padding-left: 40px;
56
}
57
.timeline figure {
58
  float: right;
59
  width: 100%;
60
}
61
.timeline article {
62
  position: relative;
63
  width: 38%;
64
  overflow: hidden;
65
  margin-bottom: 100px;
66
}
67
.timeline article:first-of-type {
68
  float: left;
69
  text-align: right;
70
}
71
.timeline article:first-of-type p,
72
.timeline article:first-of-type figure {
73
  float: right;
74
}
75
.timeline article:last-of-type {
76
  float: right;
77
}
78
.timeline article:last-of-type h2 {
79
  color: #c6e0aa;
80
}
81
.timeline article:last-of-type h6,
82
.timeline article:last-of-type a {
83
  color: #40aa00;
84
}
85
.timeline article:last-of-type a:hover {
86
  color: #95D40D;
87
}
88
 
 
JavaScript
function Timeline(cvs) {
1
function Timeline(cvs) {
2
 
3
    var self = this,
4
        paused = true,
5
        rafid = 0,
6
        mouse = { x: 0, y: 0 },
7
        canvas = cvs,
8
        ctx = null;
9
 
10
    self.lines = [];
11
 
12
    self.isOK = false;
13
    self.options = {
14
        speed: 0.1,
15
        density: 8,
16
        radius: 600,
17
    };
18
    self.targets = [
19
        [29, 32, 48, 68],
20
        [29, 33, 38]
21
    ];
22
    self.dotColors = [
23
        ['#13669b', 'rgba(19, 102, 155, 0.3)', 'rgba(19, 102, 155, 0.08)'],
24
        ['#7dd317', 'rgba(113, 222, 15, 0.3)', 'rgba(91, 164, 22, 0.12)'],
25
    ];
26
 
27
    self.isPaused = function () {
28
        return paused;
29
    };
30
 
31
    function InitDots() {
32
        var tl = $('.timeline');
33
        var top = tl.find('h2').outerHeight();
34
 
35
        self.lines[0].dots = [];
36
        var y = top;
37
        tl.find('article:first figure').each(function () {
38
 
39
            self.lines[0].dots.push([$(this).outerWidth() + 20, y + 20]);
40
 
41
            y += $(this).outerHeight();
42
        });
43
 
44
        self.lines[1].dots = [];
45
        var y = top;
46
        tl.find('article:last figure').each(function () {
47
 
48
            self.lines[1].dots.push([canvas.width - $(this).outerWidth() - 20, y + 20]);
49
 
50
            y += $(this).outerHeight();
51
        });
52
    }
53
 
54
    function OnResize() {
55
        canvas.width = canvas.offsetWidth;
56
        canvas.height = canvas.offsetHeight;
57
 
58
        var wasPaused = paused;
59
        self.toggle(false);
60
        // Init lines
61
        self.lines[0].reset(canvas.offsetWidth / 2 - 15);
62
        self.lines[1].reset(canvas.offsetWidth / 2 + 15);
63
 
64
        InitDots();
65
 
66
        self.toggle(!wasPaused);
67
    }
68
 
69
    function init() {
70
        var result = false;
71
        try {
72
            result = !!(canvas.getContext && (ctx = canvas.getContext('2d')));
73
 
74
            self.lines[0] = new Line(0, canvas.offsetHeight - 100, '#4789a3', self.options, mouse);
75
            self.lines[1] = new Line(0, canvas.offsetHeight - 100, '#a0d59c', self.options, mouse);
76
 
77
        } catch (e) {
78
            return false;
79
        }
80
 
81
        $(canvas).mousemove(function (e) {
82
 
83
            if (e.offsetX) {
84
                mouse.x = e.offsetX;
85
                mouse.y = e.offsetY;
86
            }
87
            else if (e.layerX) {
88
                mouse.x = e.layerX;
89
                mouse.y = e.layerY;
90
            }
91
            else {
92
                mouse.x = e.pageX - $(canvas).offset().left;
93
                mouse.y = e.pageY - $(canvas).offset().top;
94
            }
95
        });
96
 
97
        $(window).resize(OnResize);
98
 
99
        OnResize();
100
 
101
        return result;
102
    }
103
 
104
    function Line(y, height, color, options, mouse) {
105
        var self = this;
106
 
107
        self.color = color;
108
        self.options = options;
109
        self.mouse = mouse;
110
        self.height = height;
111
        self.dots = [];
112
        self.y = y;
113
 
114
        self.points = [];
115
 
116
        self.reset = function (x, f) {
117
            self.points = [];
118
            for (var y = self.y; y < self.height; y += self.options.density)
119
                self.points.push(new Point(x, y, self.color));
120
        }
121
 
122
        self.update = function () {
123
            for (var i = 0; i < self.points.length; i++)
124
                self.points[i].update(self.mouse, self.options);
125
        }
126
 
127
        function Point(x, y) {
128
            this.y = y;
129
            this.x = x;
130
            this.base = { x: x, y: y };
131
 
132
            this.update = function (mouse, options) {
133
                var dx = this.x - mouse.x,
134
                    dy = this.y - mouse.y,
135
                    alpha = Math.atan2(dx, dy),
136
                    alpha = (alpha > 0 ? alpha : 2 * Math.PI + alpha),
137
                    d = options.radius / Math.sqrt(dx * dx + dy * dy);
138
 
139
                this.y += Math.cos(alpha) * d + (this.base.y - this.y) * options.speed;
140
                this.x += Math.sin(alpha) * d + (this.base.x - this.x) * options.speed;
141
            }
142
        }
143
    }
144
 
145
    function drawCircle(p, r, color) {
146
        ctx.fillStyle = color;
147
        ctx.beginPath();
148
        ctx.arc(p.x, p.y, r, 0, 2 * Math.PI, true);
149
        ctx.closePath();
150
        ctx.fill();
151
    }
152
 
153
    function drawLine(p1, p2) {
154
        ctx.beginPath();
155
        ctx.moveTo(p1.x, p1.y);
156
        ctx.lineTo(p2.x, p2.y);
157
        ctx.stroke();
158
        ctx.closePath();
159
    }
160
 
161
    function redraw() {
162
        ctx.clearRect(0, 0, canvas.width, canvas.height);
163
 
164
        for (var i = 0; i < 2; i++) {
165
            var points = self.lines[i].points;
166
 
167
            ctx.beginPath();
168
            ctx.lineWidth = 2;
169
            ctx.strokeStyle = self.lines[i].color;
170
            ctx.moveTo(points[15].x, points[15].y);
171
 
172
            for (var j = 15; j < points.length - 2; j++) {
173
                var point = points[j];
174
 
175
                var xc = (points[j + 1].x + point.x) / 2;
176
                var yc = (points[j + 1].y + point.y) / 2;
177
 
178
 
179
                ctx.quadraticCurveTo(point.x, point.y, xc, yc);
180
            }
181
            ctx.stroke();
182
            ctx.closePath();
183
 
184
 
185
            // Dots
186
            ctx.lineWidth = 1.2;
187
            ctx.strokeStyle = self.dotColors[i][2];
188
            for (var j = 0; j < self.lines[i].dots.length; j++) {
189
                var dot = self.lines[i].dots[j],
190
                    id = self.targets[i][j];
191
                    dot2 = [
192
                        (self.lines[i].points[id].x + self.lines[i].points[id + 1].x) / 2,
193
                        (self.lines[i].points[id].y + self.lines[i].points[id + 1].y) / 2,
194
                    ];
195
 
196
                var p1 = { x: dot[0], y: dot[1] };
197
                var p2 = { x: dot2[0], y: dot2[1] };
198
 
199
 
200
                drawLine(p1, p2);
201
                drawCircle(p1, 3, self.dotColors[i][0]);
202
 
203
                drawCircle(p2, 11, self.dotColors[i][1]);
204
                drawCircle(p2, 5.5, self.dotColors[i][0]);
205
            }
206
        }
207
    }
208
 
209
    function animate() {
210
        rafid = requestAnimationFrame(animate);
211
 
212
        self.lines[0].update();
213
        self.lines[1].update();
214
 
215
        redraw();
216
    }
217
 
218
    self.toggle = function (run) {
219
        if (!self.isOK) return false;
220
 
221
        if (run === undefined)
222
            self.toggle(!paused);
223
 
224
        else if (!!run && paused) {
225
            paused = false;
226
            animate();
227
        }
228
        else if (!!!run) {
229
            paused = true;
230
            cancelAnimationFrame(rafid);
231
        }
232
        return true;
233
    }
234
 
235
    self.isOK = init();
236
}
237
new Timeline($('#cvs3').get(0)).toggle(true);
238
 
 

Timeline

CSSDeck G+