Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolly fixes and performance improvements #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css">

<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" defer></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" defer></script>
<script src="{{- 'assets/js/jquery.scrolly.min.js' | relative_url -}}" defer></script>
<script src="{{- 'assets/js/jquery.scrollzer.min.js' | relative_url -}}" defer></script>
<script src="{{- 'assets/js/jquery.scrollex.min.js' | relative_url -}}" defer></script>
<script src="{{- 'assets/js/skel.min.js' | relative_url -}}" defer></script>
<script src="{{- 'assets/js/util.js' | relative_url -}}" defer></script>
<!--[if lte IE 8]><script src="{{- 'assets/js/ie/respond.min.js' | relative_url -}}" defer></script><![endif]-->
Expand Down
2 changes: 2 additions & 0 deletions assets/js/jquery.scrollex.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions assets/js/jquery.scrollzer.min.js

This file was deleted.

86 changes: 61 additions & 25 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,86 @@
);
});

// Scrolly links.
$('.scrolly').scrolly();

// Nav.
var $nav_a = $('#nav a.scrolly');

// Scrolly-fy links.
$nav_a
.scrolly()
.on('click', function(e) {
.addClass('scrolly')
.on('click', function(e) {

var t = $(this),
href = t.attr('href');
var $this = $(this);

if (href[0] != '#')
return;
// External link? Bail.
if ($this.attr('href').charAt(0) != '#')
return false;

e.preventDefault();
// Prevent default.
e.preventDefault();

// Clear active and lock scrollzer until scrolling has stopped
$nav_a
.removeClass('active')
.addClass('scrollzer-locked');
if ($this.hasClass("active"))
return false;
// Deactivate all links.
$nav_a.removeClass('active');
$nav_a.removeClass('active-locked');

// Set this link to active
t.addClass('active');
// Activate link *and* lock it (so Scrollex doesn't try to activate other links as we're scrolling to this one's section).

});
$this
.addClass('active')
.addClass('active-locked');
//Return false essentially calls both preventDefault() and stopPropagation()
return false;

})

// Initialize scrollzer.
var ids = [];

$nav_a.each(function() {
.each(function() {

var $this = $(this),
id = $this.attr('href'),
$section = $(id);

// No section for this link? Bail.
if ($section.length < 1)
return;

// Scrollex.
$section.scrollex({
mode: 'middle',
top: '-10vh',
bottom: '-10vh',
initialize: function() {

var href = $(this).attr('href');
// Deactivate section.
$section.addClass('inactive');

if (href[0] != '#')
return;
},
enter: function() {

ids.push(href.substring(1));
// Activate section.
$section.removeClass('inactive');

});
// No locked links? Deactivate all links and activate this section's one.
if ($nav_a.filter('.active-locked').length == 0) {

$nav_a.removeClass('active');
$this.addClass('active');

}

// Otherwise, if this section's link is the one that's locked, unlock it.
else if ($this.hasClass('active-locked'))
$this.removeClass('active-locked');

}
});
});

// Scrolly links.
$('.scrolly').scrolly();

$.scrollzer(ids, { pad: 200, lastHack: true });

// Header (narrower + mobile).

Expand Down