Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Commit

Permalink
Deselect all if no target is in view
Browse files Browse the repository at this point in the history
  • Loading branch information
Emre Koc committed Jun 9, 2017
1 parent becf68a commit 5592575
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 11 additions & 1 deletion dist/navigate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* navigate.js
* Animated navigation on one-pagers using anchors.
*
* @version 1.0.5
* @version 1.0.6
* @author Emre Koc <[email protected]>
*/
'use strict';
Expand Down Expand Up @@ -117,11 +117,13 @@ function resizeCalculate() {
function scroll() {
if (!animating) {
var i = void 0,
b = void 0,
item = void 0,
top = $window.scrollTop() + changePoint;
for (i = items.length - 1; i >= 0; i--) {
item = items[i];
if (item.top <= top) {
b = true;
if (hash != item.id) {
if (options.history) {
change(item.hash, true);
Expand All @@ -132,6 +134,14 @@ function scroll() {
break;
}
}

if (!b) {
if (hash) {
change('#', true);
} else {
select();
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "navigate.js",
"version": "1.0.5",
"version": "1.0.6",
"description": "Animated navigation on one-pagers using anchors.",
"main": "dist/navigate.js",
"license": "MIT",
Expand Down
11 changes: 10 additions & 1 deletion src/navigate.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ function resizeCalculate() {

function scroll() {
if (!animating) {
let i, item, top = $window.scrollTop() + changePoint;
let i, b, item, top = $window.scrollTop() + changePoint;
for (i=items.length-1; i>=0; i--) {
item = items[i];
if (item.top <= top) {
b = true;
if (hash != item.id) {
if (options.history) {
change(item.hash, true);
Expand All @@ -113,6 +114,14 @@ function scroll() {
break;
}
}

if (!b) {
if (hash) {
change('#', true);
} else {
select();
}
}
}
}

Expand Down

0 comments on commit 5592575

Please sign in to comment.