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

Commit 5592575

Browse files
author
Emre Koc
committed
Deselect all if no target is in view
1 parent becf68a commit 5592575

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

dist/navigate.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* navigate.js
33
* Animated navigation on one-pagers using anchors.
44
*
5-
* @version 1.0.5
5+
* @version 1.0.6
66
* @author Emre Koc <[email protected]>
77
*/
88
'use strict';
@@ -117,11 +117,13 @@ function resizeCalculate() {
117117
function scroll() {
118118
if (!animating) {
119119
var i = void 0,
120+
b = void 0,
120121
item = void 0,
121122
top = $window.scrollTop() + changePoint;
122123
for (i = items.length - 1; i >= 0; i--) {
123124
item = items[i];
124125
if (item.top <= top) {
126+
b = true;
125127
if (hash != item.id) {
126128
if (options.history) {
127129
change(item.hash, true);
@@ -132,6 +134,14 @@ function scroll() {
132134
break;
133135
}
134136
}
137+
138+
if (!b) {
139+
if (hash) {
140+
change('#', true);
141+
} else {
142+
select();
143+
}
144+
}
135145
}
136146
}
137147

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "navigate.js",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Animated navigation on one-pagers using anchors.",
55
"main": "dist/navigate.js",
66
"license": "MIT",

src/navigate.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ function resizeCalculate() {
9999

100100
function scroll() {
101101
if (!animating) {
102-
let i, item, top = $window.scrollTop() + changePoint;
102+
let i, b, item, top = $window.scrollTop() + changePoint;
103103
for (i=items.length-1; i>=0; i--) {
104104
item = items[i];
105105
if (item.top <= top) {
106+
b = true;
106107
if (hash != item.id) {
107108
if (options.history) {
108109
change(item.hash, true);
@@ -113,6 +114,14 @@ function scroll() {
113114
break;
114115
}
115116
}
117+
118+
if (!b) {
119+
if (hash) {
120+
change('#', true);
121+
} else {
122+
select();
123+
}
124+
}
116125
}
117126
}
118127

0 commit comments

Comments
 (0)