Skip to content

Commit 9a9ed81

Browse files
authored
Development (cferdinandi#271)
* Updated readme * v9.3.0 a11y fix: now brings focus to all elements for better keyboard navigation experience
1 parent f0f84a1 commit 9a9ed81

File tree

8 files changed

+42
-15
lines changed

8 files changed

+42
-15
lines changed

dist/js/smooth-scroll.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.2.0: Animate scrolling to anchor links
2+
* smooth-scroll v9.3.0: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -379,12 +379,21 @@
379379
* @param {Number} endLocation Scroll to location
380380
* @param {Number} animationInterval How much to scroll on this loop
381381
*/
382-
var stopAnimateScroll = function (position, endLocation, animationInterval) {
382+
var stopAnimateScroll = function ( position, endLocation, animationInterval ) {
383383
var currentLocation = root.pageYOffset;
384-
if ( position == endLocation || currentLocation == endLocation || ( (root.innerHeight + currentLocation) >= documentHeight ) ) {
384+
if ( position == endLocation || currentLocation == endLocation || ( (root.innerHeight + currentLocation) >=
385+
386+
documentHeight ) ) {
385387
clearInterval(animationInterval);
388+
389+
// If scroll target is an anchor, bring it into focus
386390
if ( !isNum ) {
387391
anchorElem.focus();
392+
if ( document.activeElement.id !== anchorElem.id ) {
393+
anchorElem.setAttribute( 'tabindex', '-1' );
394+
anchorElem.focus();
395+
anchorElem.style.outline = 'none';
396+
}
388397
}
389398
animateSettings.callback( anchor, toggle ); // Run callbacks after animation complete
390399
}

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/smooth-scroll.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.2.0: Animate scrolling to anchor links
2+
* smooth-scroll v9.3.0: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -379,12 +379,21 @@
379379
* @param {Number} endLocation Scroll to location
380380
* @param {Number} animationInterval How much to scroll on this loop
381381
*/
382-
var stopAnimateScroll = function (position, endLocation, animationInterval) {
382+
var stopAnimateScroll = function ( position, endLocation, animationInterval ) {
383383
var currentLocation = root.pageYOffset;
384-
if ( position == endLocation || currentLocation == endLocation || ( (root.innerHeight + currentLocation) >= documentHeight ) ) {
384+
if ( position == endLocation || currentLocation == endLocation || ( (root.innerHeight + currentLocation) >=
385+
386+
documentHeight ) ) {
385387
clearInterval(animationInterval);
388+
389+
// If scroll target is an anchor, bring it into focus
386390
if ( !isNum ) {
387391
anchorElem.focus();
392+
if ( document.activeElement.id !== anchorElem.id ) {
393+
anchorElem.setAttribute( 'tabindex', '-1' );
394+
anchorElem.focus();
395+
anchorElem.style.outline = 'none';
396+
}
388397
}
389398
animateSettings.callback( anchor, toggle ); // Run callbacks after animation complete
390399
}

0 commit comments

Comments
 (0)