Skip to content

Commit 0d75c62

Browse files
committedApr 14, 2016
Merge pull request #121 from ankurMalhotra/gh-pages
Add 'back to top' link when scrolling through facilities list #53
2 parents 1daefc5 + ceede61 commit 0d75c62

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
 

‎index.html

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<div class="tab-content">
6363
<div id="facets" class="tab-pane control control-survey active"></div>
6464
<div id="list" class="tab-pane control control-sidebar"></div>
65+
<a href="#" id="back-to-top">Back to top</a>
6566
</div>
6667
<div id="map" style="display:none"></div>
6768
</div>

‎src/script.js

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ define(function(require) {
4848
require('ui/loading').attachTo('#loading');
4949
require('ui/filtering').attachTo('#message');
5050
require('ui/feedback_widget').attachTo('#feedback-modal');
51+
require('ui/back-to-top').attachTo('#back-to-top');
52+
require('ui/scroll').attachTo(document);
5153
require('ui/project').attachTo(document);
5254
require('data/facet').attachTo(document);
5355
require('data/search').attachTo(document);

‎src/ui/back-to-top.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
define(function(require, exports, module) {
2+
'use strict';
3+
var flight = require('flight');
4+
var $ = require('jquery');
5+
6+
module.exports = flight.component(function() {
7+
this.onClick = function() {
8+
$('body,html').animate({
9+
scrollTop: 0
10+
}, 1000);
11+
return false;
12+
};
13+
14+
this.after('initialize', function() {
15+
this.on('click', this.onClick);
16+
});
17+
});
18+
});

‎src/ui/scroll.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
define(function(require, exports, module) {
2+
'use strict';
3+
var flight = require('flight');
4+
var $ = require('jquery');
5+
6+
module.exports = flight.component(function() {
7+
8+
this.onScroll = function() {
9+
if (this.$node.scrollTop() >= 500) {
10+
$('#back-to-top').fadeIn(500);
11+
} else {
12+
$('#back-to-top').fadeOut(500);
13+
}
14+
};
15+
16+
this.after('initialize', function() {
17+
this.on('scroll', this.onScroll);
18+
});
19+
});
20+
});

‎styles/style.css

+15
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,21 @@ body > div.container {
362362
z-index: 999999999;
363363
}
364364

365+
#back-to-top {
366+
text-decoration: none;
367+
position: fixed;
368+
left: 0;
369+
bottom: 0;
370+
display: none;
371+
background: rgba(37, 170, 225, 0.8);
372+
color: #fff;
373+
padding: 4px 7px;
374+
font-size: 1.3em;
375+
border-top-left-radius: 5px;
376+
border-top-right-radius: 5px;
377+
z-index: 999999999;
378+
}
379+
365380
#feedback-form textarea {
366381
margin-bottom: 20px;
367382
}

0 commit comments

Comments
 (0)
Please sign in to comment.