Skip to content

Commit f38f570

Browse files
author
Chris Ferdinandi
committed
Adds focus to anchor if it's a link
1 parent c0ccbd0 commit f38f570

File tree

12 files changed

+18
-110
lines changed

12 files changed

+18
-110
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ Smooth Scroll is licensed under the [MIT License](http://gomakethings.com/mit/).
251251

252252
Smooth Scroll uses [semantic versioning](http://semver.org/).
253253

254+
* v5.2.0 - November 21, 2014
255+
* Add focus to scrolled to anchor if focusable.
254256
* v5.1.4 - October 18, 2014
255257
* Removed `.bind` dependency and polyfill.
256258
* Updated `gulpfile.js` tasks and namespacing.

dist/js/bind-polyfill.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

dist/js/bind-polyfill.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/js/smooth-scroll.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* smooth-scroll v5.1.4
2+
* smooth-scroll v5.2.0
33
* Animate scrolling to anchor links, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/smooth-scroll
55
*
@@ -278,10 +278,11 @@
278278
anchor = '#' + escapeCharacters(anchor.substr(1)); // Escape special characters and leading numbers
279279

280280
// Selectors and variables
281+
var anchorElem = document.querySelector(anchor);
281282
var fixedHeader = document.querySelector('[data-scroll-header]'); // Get the fixed header
282283
var headerHeight = fixedHeader === null ? 0 : (fixedHeader.offsetHeight + fixedHeader.offsetTop); // Get the height of a fixed header if one exists
283284
var startLocation = root.pageYOffset; // Current location on the page
284-
var endLocation = getEndLocation( document.querySelector(anchor), headerHeight, parseInt(settings.offset, 10) ); // Scroll to location
285+
var endLocation = getEndLocation( anchorElem, headerHeight, parseInt(settings.offset, 10) ); // Scroll to location
285286
var animationInterval; // interval timer
286287
var distance = endLocation - startLocation; // distance to travel
287288
var documentHeight = getDocumentHeight();
@@ -302,6 +303,7 @@
302303
var currentLocation = root.pageYOffset;
303304
if ( position == endLocation || currentLocation == endLocation || ( (root.innerHeight + currentLocation) >= documentHeight ) ) {
304305
clearInterval(animationInterval);
306+
anchorElem.focus();
305307
settings.callbackAfter( toggle, anchor ); // Run callbacks after animation complete
306308
}
307309
};

dist/js/smooth-scroll.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/js/bind-polyfill.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

docs/dist/js/bind-polyfill.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/dist/js/smooth-scroll.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* smooth-scroll v5.1.4
2+
* smooth-scroll v5.2.0
33
* Animate scrolling to anchor links, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/smooth-scroll
55
*
@@ -278,10 +278,11 @@
278278
anchor = '#' + escapeCharacters(anchor.substr(1)); // Escape special characters and leading numbers
279279

280280
// Selectors and variables
281+
var anchorElem = document.querySelector(anchor);
281282
var fixedHeader = document.querySelector('[data-scroll-header]'); // Get the fixed header
282283
var headerHeight = fixedHeader === null ? 0 : (fixedHeader.offsetHeight + fixedHeader.offsetTop); // Get the height of a fixed header if one exists
283284
var startLocation = root.pageYOffset; // Current location on the page
284-
var endLocation = getEndLocation( document.querySelector(anchor), headerHeight, parseInt(settings.offset, 10) ); // Scroll to location
285+
var endLocation = getEndLocation( anchorElem, headerHeight, parseInt(settings.offset, 10) ); // Scroll to location
285286
var animationInterval; // interval timer
286287
var distance = endLocation - startLocation; // distance to travel
287288
var documentHeight = getDocumentHeight();
@@ -302,6 +303,7 @@
302303
var currentLocation = root.pageYOffset;
303304
if ( position == endLocation || currentLocation == endLocation || ( (root.innerHeight + currentLocation) >= documentHeight ) ) {
304305
clearInterval(animationInterval);
306+
anchorElem.focus();
305307
settings.callbackAfter( toggle, anchor ); // Run callbacks after animation complete
306308
}
307309
};

0 commit comments

Comments
 (0)