1
Fork 0

Make nav title scroll or go home

This commit is contained in:
Jake Howard 2016-12-16 19:36:44 +00:00
parent 6fb084a3c8
commit b7c8f80d9a
5 changed files with 55 additions and 40 deletions

View file

@ -1,6 +1,6 @@
import './creative'; import './creative';
import ansi_up from 'ansi_up'; import ansi_up from 'ansi_up';
import { SCROLL_SPEED } from './consts';
$('.image').each(function () { // setup div-image hybrids $('.image').each(function () { // setup div-image hybrids
const ele = $(this); const ele = $(this);
@ -15,3 +15,15 @@ $('.ansi-up').each(function () {
const ele = $(this); const ele = $(this);
ele.html(ansi_up.ansi_to_html(ele.html())); ele.html(ansi_up.ansi_to_html(ele.html()));
}); });
$('.navbar-brand').bind('click', function (event) {
if ($('html').scrollTop() > NAVBAR_HEIGHT) {
$('html, body').stop().animate({
scrollTop: 0
}, SCROLL_SPEED);
} else {
window.location = '/';
}
event.preventDefault();
});

3
static/src/js/consts.js Normal file
View file

@ -0,0 +1,3 @@
export const NAVBAR_HEIGHT = $('#main-nav').height();
export const SCROLL_SPEED = 750;

View file

@ -1,37 +0,0 @@
/*!
* Start Bootstrap - Creative Bootstrap Theme (http://startbootstrap.com)
* Code licensed under the Apache License v2.0.
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
* (Edited for theorangeone.net)
*/
const NAVBAR_HEIGHT = $('#main-nav').height();
$('a.page-scroll').bind('click', function(event) {
const anchor = $(this);
$('html, body').stop().animate(
{
scrollTop: ($(anchor.attr('href')).offset().top - NAVBAR_HEIGHT)
},
750
);
event.preventDefault();
});
// Highlight the top nav as scrolling occurs
$('body').scrollspy({
target: '.navbar-fixed-top',
offset: NAVBAR_HEIGHT + 1
});
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
$('.navbar-toggle:visible').click();
});
// Offset for Main Navigation
$('#main-nav').affix({
offset: {
top: NAVBAR_HEIGHT * 1.5
}
});

View file

@ -1,4 +1,41 @@
import './creative';
import WOW from 'wow.js'; import WOW from 'wow.js';
import { NAVBAR_HEIGHT, SCROLL_SPEED } from '../consts';
new WOW().init(); new WOW().init();
/*!
* Start Bootstrap - Creative Bootstrap Theme (http://startbootstrap.com)
* Code licensed under the Apache License v2.0.
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
* (Edited for theorangeone.net)
*/
$('a.page-scroll').bind('click', function(event) {
const anchor = $(this);
$('html, body').stop().animate(
{ scrollTop: ($(anchor.attr('href')).offset().top - NAVBAR_HEIGHT) },
SCROLL_SPEED
);
event.preventDefault();
});
// Highlight the top nav as scrolling occurs
$('body').scrollspy({
target: '.navbar-fixed-top',
offset: NAVBAR_HEIGHT + 1
});
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
$('.navbar-toggle:visible').click();
});
// Offset for Main Navigation
$('#main-nav').affix({
offset: {
top: NAVBAR_HEIGHT * 1.5
}
});

View file

@ -7,7 +7,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand page-scroll" href="#page-top"> <a class="navbar-brand" href="#">
{{ django_settings.WAGTAIL_SITE_NAME }} {{ django_settings.WAGTAIL_SITE_NAME }}
</a> </a>
</div> </div>