Skip to content

Commit bb7fdf2

Browse files
author
cferdinandi
committed
v9.1.0
- Updated readme with new "Known Issue" - Added check for right-click and command/control + click before animating
1 parent cb5b1e3 commit bb7fdf2

File tree

7 files changed

+29
-20
lines changed

7 files changed

+29
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Smooth Scroll is built with modern JavaScript APIs, and uses progressive enhance
238238

239239
## Known Issues
240240

241-
If the `<body>` element has been assigned a height of `100%`, Smooth Scroll is unable to properly calculate page distances and will not scroll to the right location. The `<body>` element can have a fixed, non-percentage based height (ex. `500px`), or a height of `auto`.
241+
If the `<body>` element has been assigned a height of `100%` or `overflow: hidden`, Smooth Scroll is unable to properly calculate page distances and will not scroll to the right location. The `<body>` element can have a fixed, non-percentage based height (ex. `500px`), or a height of `auto`, and an `overflow` of `visible`.
242242

243243

244244
## Programatically adding `[data-scroll]` attributes to all anchor links

dist/js/smooth-scroll.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.0.1: Animate scrolling to anchor links
2+
* smooth-scroll v9.1.0: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -341,16 +341,13 @@
341341
*/
342342
smoothScroll.animateScroll = function ( anchor, toggle, options ) {
343343

344-
// if ( scrolling ) return;
345-
346344
// Options and overrides
347345
var overrides = getDataOptions( toggle ? toggle.getAttribute('data-options') : null );
348346
var settings = extend( settings || defaults, options || {}, overrides ); // Merge user options with defaults
349347

350348
// Selectors and variables
351349
var isNum = Object.prototype.toString.call( anchor ) === '[object Number]' ? true : false;
352-
var anchorElem = isNum ? null : anchor === '#' ? root.document.documentElement : root.document.querySelector(anchor);
353-
// var anchorElem = isNum ? null : ( anchor === '#' ? root.document.documentElement : root.document.querySelector(anchor) );
350+
var anchorElem = isNum ? null : ( anchor === '#' ? root.document.documentElement : root.document.querySelector(anchor) );
354351
if ( !isNum && !anchorElem ) return;
355352
var startLocation = root.pageYOffset; // Current location on the page
356353
if ( !fixedHeader ) { fixedHeader = root.document.querySelector( settings.selectorHeader ); } // Get the fixed header if not already set
@@ -424,12 +421,18 @@
424421
* @private
425422
*/
426423
var eventHandler = function (event) {
424+
425+
// Don't run if right-click or command/control + click
426+
if ( event.button !== 0 || event.metaKey || event.ctrlKey ) return;
427+
428+
// If a smooth scroll link, animate it
427429
var toggle = getClosest( event.target, settings.selector );
428430
if ( toggle && toggle.tagName.toLowerCase() === 'a' ) {
429431
event.preventDefault(); // Prevent default click event
430432
var hash = smoothScroll.escapeCharacters( toggle.hash ); // Escape hash characters
431433
smoothScroll.animateScroll( hash, toggle, settings); // Animate scroll
432434
}
435+
433436
};
434437

435438
/**

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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.0.1: Animate scrolling to anchor links
2+
* smooth-scroll v9.1.0: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -341,16 +341,13 @@
341341
*/
342342
smoothScroll.animateScroll = function ( anchor, toggle, options ) {
343343

344-
// if ( scrolling ) return;
345-
346344
// Options and overrides
347345
var overrides = getDataOptions( toggle ? toggle.getAttribute('data-options') : null );
348346
var settings = extend( settings || defaults, options || {}, overrides ); // Merge user options with defaults
349347

350348
// Selectors and variables
351349
var isNum = Object.prototype.toString.call( anchor ) === '[object Number]' ? true : false;
352-
var anchorElem = isNum ? null : anchor === '#' ? root.document.documentElement : root.document.querySelector(anchor);
353-
// var anchorElem = isNum ? null : ( anchor === '#' ? root.document.documentElement : root.document.querySelector(anchor) );
350+
var anchorElem = isNum ? null : ( anchor === '#' ? root.document.documentElement : root.document.querySelector(anchor) );
354351
if ( !isNum && !anchorElem ) return;
355352
var startLocation = root.pageYOffset; // Current location on the page
356353
if ( !fixedHeader ) { fixedHeader = root.document.querySelector( settings.selectorHeader ); } // Get the fixed header if not already set
@@ -424,12 +421,18 @@
424421
* @private
425422
*/
426423
var eventHandler = function (event) {
424+
425+
// Don't run if right-click or command/control + click
426+
if ( event.button !== 0 || event.metaKey || event.ctrlKey ) return;
427+
428+
// If a smooth scroll link, animate it
427429
var toggle = getClosest( event.target, settings.selector );
428430
if ( toggle && toggle.tagName.toLowerCase() === 'a' ) {
429431
event.preventDefault(); // Prevent default click event
430432
var hash = smoothScroll.escapeCharacters( toggle.hash ); // Escape hash characters
431433
smoothScroll.animateScroll( hash, toggle, settings); // Animate scroll
432434
}
435+
433436
};
434437

435438
/**

0 commit comments

Comments
 (0)