From 80a2d6ba807250dd5e2260900edd999e384c2b35 Mon Sep 17 00:00:00 2001
From: Chris Ferdinandi
Date: Sat, 9 Nov 2013 11:20:34 -0500
Subject: [PATCH 001/285] Converted from spaces to tabs
---
index.html | 52 +++++++--------
smooth-scroll.js | 162 +++++++++++++++++++++++------------------------
2 files changed, 107 insertions(+), 107 deletions(-)
diff --git a/index.html b/index.html
index f4c12e2..5d23558 100644
--- a/index.html
+++ b/index.html
@@ -1,47 +1,47 @@
-
- Smooth Scroll - A simple vanilla JS script to animate scrolling to anchor links.
-
-
-
-
+
+ Smooth Scroll - A simple vanilla JS script to animate scrolling to anchor links.
+
+
+
+
- Smooth Scroll
- A simple vanilla JS script to animate scrolling to anchor links.
+ Smooth Scroll
+ A simple vanilla JS script to animate scrolling to anchor links.
- Bazinga Booya
+ Bazinga Booya
-
- .
.
.
.
.
.
.
.
.
.
.
.
.
- .
.
.
.
.
.
.
.
.
.
.
.
.
- .
.
.
.
.
.
.
.
.
.
.
.
.
-
+
+ .
.
.
.
.
.
.
.
.
.
.
.
.
+ .
.
.
.
.
.
.
.
.
.
.
.
.
+ .
.
.
.
.
.
.
.
.
.
.
.
.
+
- Bazinga!
+ Bazinga!
-
- .
.
.
.
.
.
.
.
.
.
.
.
.
- .
.
.
.
.
.
.
.
.
.
.
.
.
- .
.
.
.
.
.
.
.
.
.
.
.
.
-
+
+ .
.
.
.
.
.
.
.
.
.
.
.
.
+ .
.
.
.
.
.
.
.
.
.
.
.
.
+ .
.
.
.
.
.
.
.
.
.
.
.
.
+
- Booya!
+ Booya!
- Back to the top
+ Back to the top
-
-
+
+
diff --git a/smooth-scroll.js b/smooth-scroll.js
index 17dd563..ea32957 100644
--- a/smooth-scroll.js
+++ b/smooth-scroll.js
@@ -1,90 +1,90 @@
/* =============================================================
- Smooth Scroll 2.3
- Animate scrolling to anchor links, by Chris Ferdinandi.
- http://gomakethings.com
+ Smooth Scroll 2.3
+ Animate scrolling to anchor links, by Chris Ferdinandi.
+ http://gomakethings.com
+
+ Free to use under the MIT License.
+ http://gomakethings.com/mit/
- Free to use under the MIT License.
- http://gomakethings.com/mit/
-
* ============================================================= */
(function() {
- 'use strict';
-
- // Feature Test
- if ( 'querySelector' in document && 'addEventListener' in window && Array.prototype.forEach ) {
-
- // Function to animate the scroll
- var smoothScroll = function (anchor, duration) {
-
- // Calculate how far and how fast to scroll
- var startLocation = window.pageYOffset;
- var endLocation = anchor.offsetTop;
- var distance = endLocation - startLocation;
- var increments = distance/(duration/16);
- var stopAnimation;
-
- // Scroll the page by an increment, and check if it's time to stop
- var animateScroll = function () {
- window.scrollBy(0, increments);
- stopAnimation();
- };
-
- // If scrolling down
- if ( increments >= 0 ) {
- // Stop animation when you reach the anchor OR the bottom of the page
- stopAnimation = function () {
- var travelled = window.pageYOffset;
- if ( (travelled >= (endLocation - increments)) || ((window.innerHeight + travelled) >= document.body.offsetHeight) ) {
- clearInterval(runAnimation);
- }
- };
- }
- // If scrolling up
- else {
- // Stop animation when you reach the anchor OR the top of the page
- stopAnimation = function () {
- var travelled = window.pageYOffset;
- if ( travelled <= (endLocation || 0) ) {
- clearInterval(runAnimation);
- }
- };
- }
-
- // Loop the animation function
- var runAnimation = setInterval(animateScroll, 16);
-
- };
-
- // Define smooth scroll links
- var scrollToggle = document.querySelectorAll('.scroll');
-
- // For each smooth scroll link
- [].forEach.call(scrollToggle, function (toggle) {
-
- // When the smooth scroll link is clicked
- toggle.addEventListener('click', function(e) {
-
- // Prevent the default link behavior
- e.preventDefault();
-
- // Get anchor link and calculate distance from the top
- var dataID = toggle.getAttribute('href');
- var dataTarget = document.querySelector(dataID);
- var dataSpeed = toggle.getAttribute('data-speed');
-
- // If the anchor exists
- if (dataTarget) {
- // Scroll to the anchor
- smoothScroll(dataTarget, dataSpeed || 500);
- }
-
- }, false);
-
- });
-
- }
+ 'use strict';
+
+ // Feature Test
+ if ( 'querySelector' in document && 'addEventListener' in window && Array.prototype.forEach ) {
+
+ // Function to animate the scroll
+ var smoothScroll = function (anchor, duration) {
+
+ // Calculate how far and how fast to scroll
+ var startLocation = window.pageYOffset;
+ var endLocation = anchor.offsetTop;
+ var distance = endLocation - startLocation;
+ var increments = distance/(duration/16);
+ var stopAnimation;
+
+ // Scroll the page by an increment, and check if it's time to stop
+ var animateScroll = function () {
+ window.scrollBy(0, increments);
+ stopAnimation();
+ };
+
+ // If scrolling down
+ if ( increments >= 0 ) {
+ // Stop animation when you reach the anchor OR the bottom of the page
+ stopAnimation = function () {
+ var travelled = window.pageYOffset;
+ if ( (travelled >= (endLocation - increments)) || ((window.innerHeight + travelled) >= document.body.offsetHeight) ) {
+ clearInterval(runAnimation);
+ }
+ };
+ }
+ // If scrolling up
+ else {
+ // Stop animation when you reach the anchor OR the top of the page
+ stopAnimation = function () {
+ var travelled = window.pageYOffset;
+ if ( travelled <= (endLocation || 0) ) {
+ clearInterval(runAnimation);
+ }
+ };
+ }
+
+ // Loop the animation function
+ var runAnimation = setInterval(animateScroll, 16);
+
+ };
+
+ // Define smooth scroll links
+ var scrollToggle = document.querySelectorAll('.scroll');
+
+ // For each smooth scroll link
+ [].forEach.call(scrollToggle, function (toggle) {
+
+ // When the smooth scroll link is clicked
+ toggle.addEventListener('click', function(e) {
+
+ // Prevent the default link behavior
+ e.preventDefault();
+
+ // Get anchor link and calculate distance from the top
+ var dataID = toggle.getAttribute('href');
+ var dataTarget = document.querySelector(dataID);
+ var dataSpeed = toggle.getAttribute('data-speed');
+
+ // If the anchor exists
+ if (dataTarget) {
+ // Scroll to the anchor
+ smoothScroll(dataTarget, dataSpeed || 500);
+ }
+
+ }, false);
+
+ });
+
+ }
})();
\ No newline at end of file
From 7f8935cc038848949dfb247689c4ef139ad3359d Mon Sep 17 00:00:00 2001
From: Chris Ferdinandi
Date: Thu, 21 Nov 2013 15:00:25 -0500
Subject: [PATCH 002/285] Added easing support
---
README.md | 2 ++
index.html | 37 ++++++++++++++++++++++++++-----
smooth-scroll.js | 57 ++++++++++++++++++++++++++++++++++--------------
3 files changed, 74 insertions(+), 22 deletions(-)
mode change 100644 => 100755 smooth-scroll.js
diff --git a/README.md b/README.md
index 8c37b6d..13f9d48 100755
--- a/README.md
+++ b/README.md
@@ -5,6 +5,8 @@ A simple script to animate scrolling to anchor links.
Getting started with Smooth Scroll is really easy. [View the online tutorial](http://cferdinandi.github.com/smooth-scroll/) or dig through the `index.html` file.
## Changelog
+* v2.4 (November 21, 2013)
+ * Added easing support with contributions from [Willem Liu](https://github.com/willemliu) and code from [Gaëtan Renaudeau](https://gist.github.com/gre/1650294).
* v2.3 (August 27, 2013)
* Added missing semicolons.
* Defined `animationStop` variable once, add values later.
diff --git a/index.html b/index.html
index 5d23558..11f55bd 100644
--- a/index.html
+++ b/index.html
@@ -15,9 +15,36 @@
- Booya!
-
- Back to the top
+ Back to the top
@@ -44,4 +69,4 @@ Smooth Scroll