From f769ac1f9206a0f3199b90bd0b36caf0d8cd3e44 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 16 Jan 2014 09:39:12 -0800 Subject: [PATCH 01/79] scrollReveal.js initial commit --- README.md | 92 +++++++++++++++ index.html | 52 +++++++++ scrollReveal.js | 299 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 443 insertions(+) create mode 100644 README.md create mode 100644 index.html create mode 100644 scrollReveal.js diff --git a/README.md b/README.md new file mode 100644 index 00000000..50fe39a3 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +#scrollReveal.js +####Declarative CSS3 transitions on scroll. +A simple way to create and maintain how your elements reveal, triggered when your element(s) enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) + +> ***Disclaimer:** This is a brand new project and still under active development. Please bare in mind that this plug-in will be updated frequently, and that breaking changes are virtually guaranteed in the next couple iterations. + +##1. Installation +Please download `scrollReveal.js` into your JavaScript folder, and reference it just after the closing `` tag. It will automatically instantiate itself ready-to-go when the event `DOMContentReady` fires. + + +``` + // Everything else + // ... + + + +``` + +>**NOTE:** scrollReveal.js does not require jQuery, but *does* rely upon CSS3 transitions; it has been developed exclusively for modern browser use only. + + +##2. Usage +By adding a `data-scrollreveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport.

**Fig 1**: + +``` +

Welcome Traveler

+``` +However, scrollReveal.js allows you to describe custom reveal behavior, using *natural language*.

**Fig 2**: +``` +

Welcome

+

Hello

+ +``` + + + +###2.1 Keywords +Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific keywords: **tokens** that expect to be followed by a **value**, and semantic **fillers** that facilitate the use of more natural language. + +####2.1.1 Tokens +These words describe the reveal behavior, using **keyword** / **value** pairs. + +--- + +- **Enter** — Controls the direction of your element transition. Whatever value is passed is considered the vector origin. For example, specifying `top` will reveal your element with a downward motion. + * Accepted value: `top`, `right`, `bottom` or `left` + +--- + +- **Move** — The distance your element will travel during transition. + * Accepted value: **[ integer ] px** →(eg. `move 33px`) + +--- + +- **Over** — The duration of your element’s transition. + * Accepted value: **[ decminal ] s** → (eg. `over 1.66s`) + +--- + +- **After/Wait** — The delay before your element beings its transition. + * Accepted value: **[ decminal ] s** → (eg. `after 0.33s` or `wait 0.33s`) + +--- + +#### 2.1.2 Fillers +While **keywords** must be followed by an appropriate accepted **value**, the use of conjoining **fillers** are permitted for more natural language. These are shown below: + +- `from` +- `the` +- `and` +- `then` +- `but` + +**Fig 3**: +``` + +
Example 1
+
Example 1
+ + +
Example 2
+
Example 2
+``` + +### 3. Contributions / Thanks! +I noticed a number of clients requesting CSS3 transitions on scroll for various site elements, so I created this little vanilla JavaScript helper plug-in to help out. Many thanks to Codrops, Mary Lou and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, Codrops. + +#####**If you’d like to contribute, please feel free!** + +© 2014 Julian Lloyd +Licensed under the MIT license. +[http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) diff --git a/index.html b/index.html new file mode 100644 index 00000000..7397d6db --- /dev/null +++ b/index.html @@ -0,0 +1,52 @@ + + + + + scrollReveal.js + + + + +
Default
+
Enter Top and Move 25px
+
Enter Bottom Over 1s
+
Enter Left and Move 25px
+
Enter Right Over 1s
+ +
+ +
Default
+
Enter Top and Move 25px
+
Enter Bottom Over 1s
+
Enter Left and Move 25px
+
Enter Right Over 1s
+ +
+ + +
Default
+
Enter Top and Move 25px
+
Enter Bottom Over 1s
+
Enter Left and Move 25px
+
Enter Right Over 1s
+ +
+ + + + + \ No newline at end of file diff --git a/scrollReveal.js b/scrollReveal.js new file mode 100644 index 00000000..b502efed --- /dev/null +++ b/scrollReveal.js @@ -0,0 +1,299 @@ +/* + _ _ _____ _ _ + | | | __ \ | | (_) + ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ + / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| + \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ + _/ | + |__/ + + "Declarative CSS3 transitions on scroll." + +/*============================================================================= + + scrollReveal.js is inspired by cbpScroller.js, © 2014, Codrops. + + Licensed under the MIT license. + http://www.opensource.org/licenses/mit-license.php + + scrollReveal.js, © 2014 http://julianlloyd.me + +=============================================================================*/ + +;(function (window) { + + 'use strict'; + + var docElem = window.document.documentElement; + + function getViewportH () { + var client = docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + } + + function getOffset (el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) + + return { + top: offsetTop, + left: offsetLeft + } + } + + function isElementInViewport (el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + getViewportH(), + elH = el.offsetHeight, + elTop = getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + } + + function extend (a, b) { + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; + } + + + function scrollReveal(options) { + this.options = extend(this.defaults, options); + this._init(); + } + + + + scrollReveal.prototype = { + defaults: { + axis: 'y', + distance: '25px', + duration: '0.66s', + delay: '0s', + + // if 0, the element is considered in the viewport as soon as it enters + // if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33 + }, + + /*=============================================================================*/ + + _init: function () { + + var self = this; + + this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); + this.scrolled = false; + + // Initialize all scrollreveals, triggering all + // reveals on visible elements. + this.elems.forEach(function (el, i) { + self.animate(el); + }); + + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; + + var resizeHandler = function () { + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + self.resizeTimeout = setTimeout(delayed, 200); + }; + + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, + + /*=============================================================================*/ + + _scrollPage: function () { + var self = this; + + this.elems.forEach(function (el, i) { + if (isElementInViewport(el, self.options.viewportFactor)) { + self.animate(el); + } + }); + this.scrolled = false; + }, + + /*=============================================================================*/ + + parseLanguage: function (el) { + + // Splits on a sequence of one or more commas, periods or spaces. + var words = el.getAttribute('data-scrollreveal').split(/[,. ]+/), + enterFrom, + parsed = {}; + + function filter (words) { + var ret = [], + + blacklist = [ + "from", + "the", + "and", + "then", + "but" + ]; + + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); + + return ret; + } + + words = filter(words); + + words.forEach(function (word, i) { + + switch (word) { + case "enter": + enterFrom = words[i + 1]; + + if (enterFrom == "top" || enterFrom == "bottom") { + parsed.axis = "y"; + } + + if (enterFrom == "left" || enterFrom == "right") { + parsed.axis = "x"; + } + + break; + + case "after": + parsed.delay = words[i + 1]; + break; + + case "wait": + parsed.delay = words[i + 1]; + break; + + case "move": + parsed.distance = words[i + 1]; + break; + + case "over": + parsed.duration = words[i + 1]; + break; + + case "trigger": + parsed.eventName = words[i + 1]; + break; + + default: + // Unrecognizable words; do nothing. + break; + } + }); + + // After all values are parsed, let’s make sure our our + // pixel distance is negative for top and left entrances. + // + // ie. "move 25px from top" starts at 'top: -25px' in CSS. + + if (enterFrom == "top" || enterFrom == "left") { + + if (!typeof parsed.distance == "undefined") { + parsed.distance = "-" + parsed.distance; + } + + else { + parsed.distance = "-" + this.options.distance; + } + + } + + return parsed; + }, + + /*=============================================================================*/ + + genCSS: function (el, axis) { + var parsed = this.parseLanguage(el); + + var dist = parsed.distance || this.options.distance, + dur = parsed.duration || this.options.duration, + delay = parsed.delay || this.options.delay, + axis = parsed.axis || this.options.axis; + + var transition = "-webkit-transition: all " + dur + " ease " + delay + ";" + + "-moz-transition: all " + dur + " ease " + delay + ";" + + "-o-transition: all " + dur + " ease " + delay + ";" + + "transition: all " + dur + " ease " + delay + ";"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "-moz-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "-moz-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + /*=============================================================================*/ + + animate: function (el) { + var css = this.genCSS(el); + + if (!el.getAttribute('data-sr-init')) { + el.setAttribute('style', css.initial); + el.setAttribute('data-sr-init', true); + } + + if (isElementInViewport(el, this.options.viewportFactor)) { + el.setAttribute('style', css.target + css.transition); + + setTimeout(function () { + el.removeAttribute('style'); + }, css.totalDuration); + } + + }// end animate() + }; // end scrollReveal.prototype + + document.addEventListener("DOMContentLoaded", function (evt) { + window.scrollReveal = new scrollReveal(); + }); + +})(window); \ No newline at end of file From 56b5a55065f7e1396ef3f97e2964d006a8ab831e Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 16 Jan 2014 09:42:58 -0800 Subject: [PATCH 02/79] README.md updated --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 50fe39a3..d84d82b9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ #scrollReveal.js ####Declarative CSS3 transitions on scroll. -A simple way to create and maintain how your elements reveal, triggered when your element(s) enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) +A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) -> ***Disclaimer:** This is a brand new project and still under active development. Please bare in mind that this plug-in will be updated frequently, and that breaking changes are virtually guaranteed in the next couple iterations. +> **Disclaimer:** This is a brand new project and still under active development. Please bare in mind that this plug-in will be updated frequently, and that breaking changes are virtually guaranteed in the next couple iterations. ##1. Installation Please download `scrollReveal.js` into your JavaScript folder, and reference it just after the closing `` tag. It will automatically instantiate itself ready-to-go when the event `DOMContentReady` fires. @@ -83,10 +83,12 @@ While **keywords** must be followed by an appropriate accepted **value**, the us ``` ### 3. Contributions / Thanks! -I noticed a number of clients requesting CSS3 transitions on scroll for various site elements, so I created this little vanilla JavaScript helper plug-in to help out. Many thanks to Codrops, Mary Lou and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, Codrops. +I noticed a number of clients requesting CSS3 transitions on scroll for various site elements, so I created this little vanilla JavaScript helper plug-in to help out. + +Many thanks to Codrops, Mary Lou and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, Codrops. #####**If you’d like to contribute, please feel free!** -© 2014 Julian Lloyd +© 2014 Julian Lloyd
Licensed under the MIT license. [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) From 8926db335b2125fbe0b5493516f6ada87aaa2413 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 16 Jan 2014 10:02:14 -0800 Subject: [PATCH 03/79] scrollReveal.js initial commit --- .gitignore | 4 ++++ README.md | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ac39bdd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +## generic files to ignore +*~ +*.lock +*.DS_Store diff --git a/README.md b/README.md index d84d82b9..20766322 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,11 @@ However, scrollReveal.js allows you to describe custom reveal behavior, using *n -###2.1 Keywords -Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific keywords: **tokens** that expect to be followed by a **value**, and semantic **fillers** that facilitate the use of more natural language. +###2.1 Token +Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific words: **keywords** that expect to be followed by a **value**, and semantic **fillers** that facilitate the use of more natural language. -####2.1.1 Tokens -These words describe the reveal behavior, using **keyword** / **value** pairs. +####2.1.1 keywords +These words describe the reveal behavior, using **keywords** / **value** pairs. --- @@ -89,6 +89,6 @@ Many thanks to Codrops, Mary Lou and the [cbpScroller.js](http://tympanus.net/co #####**If you’d like to contribute, please feel free!** -© 2014 Julian Lloyd
+© 2014 [@JulianLloyd](https://twitter.com/julianlloyd)
Licensed under the MIT license. [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) From bbd8493a5343b7197e6aafb5396d74af2a3fedc6 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Fri, 17 Jan 2014 20:53:59 -0800 Subject: [PATCH 04/79] scrollReveal.js initial commit --- README.md | 8 ++++---- index.html | 6 +++--- scrollReveal.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 20766322..cb23ce1f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A simple way to create and maintain how elements fade in, triggered when they en > **Disclaimer:** This is a brand new project and still under active development. Please bare in mind that this plug-in will be updated frequently, and that breaking changes are virtually guaranteed in the next couple iterations. ##1. Installation -Please download `scrollReveal.js` into your JavaScript folder, and reference it just after the closing `` tag. It will automatically instantiate itself ready-to-go when the event `DOMContentReady` fires. +Please download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate itself ready-to-go when the event `DOMContentReady` fires. ``` @@ -34,11 +34,11 @@ However, scrollReveal.js allows you to describe custom reveal behavior, using *n -###2.1 Token +###2.1 Keywords, Values and Fillers Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific words: **keywords** that expect to be followed by a **value**, and semantic **fillers** that facilitate the use of more natural language. -####2.1.1 keywords -These words describe the reveal behavior, using **keywords** / **value** pairs. +####2.1.1 Keywords and Values +These words describe the reveal behavior, using **keyword** / **value** pairs. --- diff --git a/index.html b/index.html index 7397d6db..c727a6a5 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@
Default
Enter Top and Move 25px
Enter Bottom Over 1s
-
Enter Left and Move 25px
+
Enter Top and Move 25px
Enter Right Over 1s

@@ -32,7 +32,7 @@
Default
Enter Top and Move 25px
Enter Bottom Over 1s
-
Enter Left and Move 25px
+
Enter Top and Move 25px
Enter Right Over 1s

@@ -41,7 +41,7 @@
Default
Enter Top and Move 25px
Enter Bottom Over 1s
-
Enter Left and Move 25px
+
Enter Top and Move 25px
Enter Right Over 1s

diff --git a/scrollReveal.js b/scrollReveal.js index b502efed..7f687682 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -17,7 +17,7 @@ Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php - scrollReveal.js, © 2014 http://julianlloyd.me + scrollReveal.js, © 2014 https://twitter.com/julianlloyd =============================================================================*/ From c39edb7f7fde5e2b68c10af3203416b7e10bad27 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Mon, 20 Jan 2014 01:45:25 -0800 Subject: [PATCH 05/79] scrollReveal.js initial commit --- README.md | 43 +++--- css/style.css | 322 +++++++++++++++++++++++++++++++++++++++++++++ index.html | 213 +++++++++++++++++++++++------- js/scrollReveal.js | 304 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 812 insertions(+), 70 deletions(-) create mode 100644 css/style.css create mode 100644 js/scrollReveal.js diff --git a/README.md b/README.md index cb23ce1f..f15543a6 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ ####Declarative CSS3 transitions on scroll. A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) -> **Disclaimer:** This is a brand new project and still under active development. Please bare in mind that this plug-in will be updated frequently, and that breaking changes are virtually guaranteed in the next couple iterations. +> **Disclaimer:** Please bare in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. ##1. Installation -Please download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate itself ready-to-go when the event `DOMContentReady` fires. +Clone or download download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate ready-to-go when the `DOMContentReady` event fires. ``` @@ -23,19 +23,21 @@ Please download `scrollReveal.js` into your JavaScript folder, and reference it By adding a `data-scrollreveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport.

**Fig 1**: ``` -

Welcome Traveler

+

Hello world!

``` -However, scrollReveal.js allows you to describe custom reveal behavior, using *natural language*.

**Fig 2**: +However, scrollReveal.js allows you to define custom reveal behavior, using *descriptive language*.

**Fig 2**: ``` -

Welcome

-

Hello

- +

Foo

+ +

Bar

+ + ``` ###2.1 Keywords, Values and Fillers -Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific words: **keywords** that expect to be followed by a **value**, and semantic **fillers** that facilitate the use of more natural language. +Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific words: **keywords** that expect to be followed by a **value**, and semantic **fillers** that facilitate more natural language. ####2.1.1 Keywords and Values These words describe the reveal behavior, using **keyword** / **value** pairs. @@ -43,27 +45,27 @@ These words describe the reveal behavior, using **keyword** / **value** pairs. --- - **Enter** — Controls the direction of your element transition. Whatever value is passed is considered the vector origin. For example, specifying `top` will reveal your element with a downward motion. - * Accepted value: `top`, `right`, `bottom` or `left` + * Accepted value: `top`, `right`, `bottom` or `left` → (eg. `enter top`) --- - **Move** — The distance your element will travel during transition. - * Accepted value: **[ integer ] px** →(eg. `move 33px`) + * Accepted value: **[ integer ] px** → (eg. `move 33px`) --- - **Over** — The duration of your element’s transition. - * Accepted value: **[ decminal ] s** → (eg. `over 1.66s`) + * Accepted value: **[ decimal ] s** → (eg. `over 1.66s`) --- - **After/Wait** — The delay before your element beings its transition. - * Accepted value: **[ decminal ] s** → (eg. `after 0.33s` or `wait 0.33s`) + * Accepted value: **[ decimal ] s** → (eg. `after 0.33s` or `wait 0.33s`) --- #### 2.1.2 Fillers -While **keywords** must be followed by an appropriate accepted **value**, the use of conjoining **fillers** are permitted for more natural language. These are shown below: +While **keywords** must be followed by an appropriate accepted **value**, the use of conjoining **fillers** are permitted for more readable language. These are shown below: - `from` - `the` @@ -73,21 +75,20 @@ While **keywords** must be followed by an appropriate accepted **value**, the us **Fig 3**: ``` - +
Example 1
Example 1
- -
Example 2
-
Example 2
+ +
Example 2
+
Example 2
+
Example 2
``` ### 3. Contributions / Thanks! -I noticed a number of clients requesting CSS3 transitions on scroll for various site elements, so I created this little vanilla JavaScript helper plug-in to help out. - -Many thanks to Codrops, Mary Lou and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, Codrops. +I noticed a growing number of clients were requesting on-scroll CSS3 transitions for various site elements, and so scrollReveal.js was made to help with development. If you’d like to contribute—please do! -#####**If you’d like to contribute, please feel free!** +Many thanks to [@Codrops](https://twitter.com/codrops), [@Mary Lou](https://twitter.com/crnacura) and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, [Codrops](http://tympanus.net/codrops/). © 2014 [@JulianLloyd](https://twitter.com/julianlloyd)
Licensed under the MIT license. diff --git a/css/style.css b/css/style.css new file mode 100644 index 00000000..1798e6bc --- /dev/null +++ b/css/style.css @@ -0,0 +1,322 @@ +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) +*/ +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} + +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} + +body { + line-height: 1; +} + +ol, ul { + list-style: none; +} + +blockquote, q { + quotes: none; +} + +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} + +table { + border-collapse: collapse; + border-spacing: 0; +} + +a { + cursor: pointer; +} + +* { + -moz-box-sizing: border-box; + box-sizing: border-box; +} + +html { + overflow: -moz-scrollbars-vertical; + overflow-y: scroll; +} + +h1, .h1 { + font-family: "proxima-nova", sams-serif; + font-weight: 100; +} + +html, body { + font-family: "proxima-nova", sans-serif; + font-weight: 300; +} + +.clearfix:before, +.clearfix:after { + content: " "; + display: table; +} + +.clearfix:after { + clear: both; +} + +html, body { + color: white; + text-align: center; +} +@media screen and (min-width: 300px) { + html, body { + font-size: 14px; + } +} +@media screen and (min-width: 460px) { + html, body { + font-size: 20px; + } +} +@media screen and (min-width: 900px) { + html, body { + font-size: 24px; + } +} + +h1, .h1 { + line-height: 1.166; + margin: .66em 0; +} + +@media screen and (min-width: 300px) { + h1, .h1 { + font-size: 2.33em; + } +} +@media screen and (min-width: 460px) { + h1, .h1 { + font-size: 2.66em; + } +} +@media screen and (min-width: 720px) { + h1, .h1 { + font-size: 3.33em; + } +} + +p { + color: #616c84; + margin: 0.33em 0; +} + +a:link, +a:visited { + color: #35ff99; + text-decoration: none; + border-radius: 5px; + padding: 2px; +} + +a:hover, +a:active { + background: #35ff99; + color: #202a39; +} + +small { + font-size: .75em; +} + +em { + font-style: italic; +} + +.text-left { + text-align: left; +} + +.text-right { + text-align: right; +} + +.text-center { + text-align: center; +} + +html, body { + height: 100%; + background: #202a39; +} + +.column-container { + width: 80%; + max-width: 1000px; + margin: 0 auto; + overflow: hidden; + height: 250%; + text-align: center; +} +@media screen and (min-width: 300px) { + .column-container { + padding-top: 20%; + margin-bottom: -125px; + } +} +@media screen and (min-width: 720px) { + .column-container { + padding-top: 10%; + } +} + +.column { + width: 3%; + height: 100%; + margin: 0 2%; + display: inline-block; +} + +.block { + border-radius: 5px; + margin-bottom: 150%; +} + +.block-1x { + height: 10%; +} + +.block-2x { + height: 15%; +} + +.block-3x { + height: 20%; +} + +.block-blueberry { + background: #008597; +} + +.block-slate { + background: #2d3443; +} + +.block-grape { + background: #4d407c; +} + +.block-raspberry { + background: #ff005d; +} + +.block-mango { + background: #ffcc00; +} + +.block-orange { + background: #ff7c35; +} + +.block-kiwi { + background: #35ff99; +} + +.withLove { + overflow: hidden; + text-align: center; + padding-bottom: 2em; + cursor: default; + color: #616c84; +} +@media screen and (min-width: 900px) { + .withLove { + margin-top: 125px; + } +} +.withLove * { + display: inline-block; +} +.withLove .alpha, +.withLove .omega { + width: 40%; +} +.withLove .alpha { + text-align: right; +} +.withLove .omega { + text-align: left; +} +.withLove .heart { + margin: 0 -2px; + position: relative; + z-index: 3; + -webkit-animation: throb 1.33s ease-in-out infinite; + animation: throb 1.33s ease-in-out infinite; +} +.withLove .heart path { + fill: #ff005d; +} +@media screen and (min-width: 300px) { + .withLove .heart { + width: 30px; + height: 30px; + top: .66em; + } +} +@media screen and (min-width: 460px) { + .withLove .heart { + top: .8em; + width: 50px; + height: 50px; + } +} + +@-webkit-keyframes throb { + 0% { + -webkit-transform: scale(1); + } + + 50% { + -webkit-transform: scale(0.8); + } + + 100% { + -webkit-transform: scale(1); + } +} + +@keyframes throb { + 0% { + transform: scale(1); + } + + 50% { + transform: scale(0.8); + } + + 100% { + transform: scale(1); + } +} diff --git a/index.html b/index.html index c727a6a5..05d920f0 100644 --- a/index.html +++ b/index.html @@ -1,52 +1,167 @@ - - - scrollReveal.js - - - - -
Default
-
Enter Top and Move 25px
-
Enter Bottom Over 1s
-
Enter Top and Move 25px
-
Enter Right Over 1s
- -
- -
Default
-
Enter Top and Move 25px
-
Enter Bottom Over 1s
-
Enter Top and Move 25px
-
Enter Right Over 1s
- -
- - -
Default
-
Enter Top and Move 25px
-
Enter Bottom Over 1s
-
Enter Top and Move 25px
-
Enter Right Over 1s
- -
- - - - + + scrollReveal.js + + + + + + + + + + + + + + + + + + Fork me on GitHub + + +

scrollReveal.js

+

Declarative on-scroll reveal animations.

+

An open-source project by @JulianLloyd

+ +
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ +
+ +
+ Made with + + + + + + + + in California +
+ + + + + + \ No newline at end of file diff --git a/js/scrollReveal.js b/js/scrollReveal.js new file mode 100644 index 00000000..b7c1e750 --- /dev/null +++ b/js/scrollReveal.js @@ -0,0 +1,304 @@ +/* + _ _ _____ _ _ + | | | __ \ | | (_) + ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ + / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| + \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ + _/ | + |__/ + + "Declarative on-scroll reveal animations." + +/*============================================================================= + + scrollReveal.js is inspired by cbpScroller.js, © 2014, Codrops. + + Licensed under the MIT license. + http://www.opensource.org/licenses/mit-license.php + + scrollReveal.js, © 2014 https://twitter.com/julianlloyd + +=============================================================================*/ + +;(function (window) { + + 'use strict'; + + var docElem = window.document.documentElement; + + function getViewportH () { + var client = docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + } + + function getOffset (el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) + + return { + top: offsetTop, + left: offsetLeft + } + } + + function isElementInViewport (el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + getViewportH(), + elH = el.offsetHeight, + elTop = getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + } + + function extend (a, b) { + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; + } + + + function scrollReveal(options) { + this.options = extend(this.defaults, options); + this._init(); + } + + + + scrollReveal.prototype = { + defaults: { + axis: 'y', + distance: '25px', + duration: '0.66s', + delay: '0s', + + // if 0, the element is considered in the viewport as soon as it enters + // if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33 + }, + + /*=============================================================================*/ + + _init: function () { + + var self = this; + + this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); + this.scrolled = false; + + // Initialize all scrollreveals, triggering all + // reveals on visible elements. + this.elems.forEach(function (el, i) { + self.animate(el); + }); + + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; + + var resizeHandler = function () { + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + self.resizeTimeout = setTimeout(delayed, 200); + }; + + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, + + /*=============================================================================*/ + + _scrollPage: function () { + var self = this; + + this.elems.forEach(function (el, i) { + if (isElementInViewport(el, self.options.viewportFactor)) { + self.animate(el); + } + }); + this.scrolled = false; + }, + + /*=============================================================================*/ + + parseLanguage: function (el) { + + // Splits on a sequence of one or more commas, periods or spaces. + var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + enterFrom, + parsed = {}; + + function filter (words) { + var ret = [], + + blacklist = [ + "from", + "the", + "and", + "then", + "but" + ]; + + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); + + return ret; + } + + words = filter(words); + + words.forEach(function (word, i) { + + switch (word) { + case "enter": + enterFrom = words[i + 1]; + + if (enterFrom == "top" || enterFrom == "bottom") { + parsed.axis = "y"; + } + + if (enterFrom == "left" || enterFrom == "right") { + parsed.axis = "x"; + } + + return; + + case "after": + parsed.delay = words[i + 1]; + return; + + case "wait": + parsed.delay = words[i + 1]; + return; + + case "move": + parsed.distance = words[i + 1]; + return; + + case "over": + parsed.duration = words[i + 1]; + return; + + case "trigger": + parsed.eventName = words[i + 1]; + return; + + default: + // Unrecognizable words; do nothing. + return; + } + }); + + // After all values are parsed, let’s make sure our our + // pixel distance is negative for top and left entrances. + // + // ie. "move 25px from top" starts at 'top: -25px' in CSS. + + if (enterFrom == "top" || enterFrom == "left") { + + if (!typeof parsed.distance == "undefined") { + parsed.distance = "-" + parsed.distance; + } + + else { + parsed.distance = "-" + this.options.distance; + } + + } + + return parsed; + }, + + /*=============================================================================*/ + + genCSS: function (el, axis) { + var parsed = this.parseLanguage(el); + + var dist = parsed.distance || this.options.distance, + dur = parsed.duration || this.options.duration, + delay = parsed.delay || this.options.delay, + axis = parsed.axis || this.options.axis; + + var transition = "-webkit-transition: all " + dur + " ease " + delay + ";" + + "-moz-transition: all " + dur + " ease " + delay + ";" + + "-o-transition: all " + dur + " ease " + delay + ";" + + "transition: all " + dur + " ease " + delay + ";"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "-moz-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "-moz-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + /*=============================================================================*/ + + animate: function (el) { + var css = this.genCSS(el); + + if (!el.getAttribute('data-sr-init')) { + el.setAttribute('style', css.initial); + el.setAttribute('data-sr-init', true); + } + + if (el.getAttribute('data-sr-complete')) { + return; + } + + if (isElementInViewport(el, this.options.viewportFactor)) { + el.setAttribute('style', css.target + css.transition); + + setTimeout(function () { + el.removeAttribute('style'); + el.setAttribute('data-sr-complete', true); + }, css.totalDuration); + } + + } + }; // end scrollReveal.prototype + + document.addEventListener("DOMContentLoaded", function (evt) { + window.scrollReveal = new scrollReveal(); + }); + +})(window); \ No newline at end of file From 146e1cb578b01600a115046b8ec149062df2650d Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Mon, 20 Jan 2014 01:47:00 -0800 Subject: [PATCH 06/79] scrollReveal.js initial commit --- scrollReveal.js | 299 ------------------------------------------------ 1 file changed, 299 deletions(-) delete mode 100644 scrollReveal.js diff --git a/scrollReveal.js b/scrollReveal.js deleted file mode 100644 index 7f687682..00000000 --- a/scrollReveal.js +++ /dev/null @@ -1,299 +0,0 @@ -/* - _ _ _____ _ _ - | | | __ \ | | (_) - ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ - / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| - \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ - _/ | - |__/ - - "Declarative CSS3 transitions on scroll." - -/*============================================================================= - - scrollReveal.js is inspired by cbpScroller.js, © 2014, Codrops. - - Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php - - scrollReveal.js, © 2014 https://twitter.com/julianlloyd - -=============================================================================*/ - -;(function (window) { - - 'use strict'; - - var docElem = window.document.documentElement; - - function getViewportH () { - var client = docElem['clientHeight'], - inner = window['innerHeight']; - - return (client < inner) ? inner : client; - } - - function getOffset (el) { - var offsetTop = 0, - offsetLeft = 0; - - do { - if (!isNaN(el.offsetTop)) { - offsetTop += el.offsetTop; - } - if (!isNaN(el.offsetLeft)) { - offsetLeft += el.offsetLeft; - } - } while (el = el.offsetParent) - - return { - top: offsetTop, - left: offsetLeft - } - } - - function isElementInViewport (el, h) { - var scrolled = window.pageYOffset, - viewed = scrolled + getViewportH(), - elH = el.offsetHeight, - elTop = getOffset(el).top, - elBottom = elTop + elH, - h = h || 0; - - return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - } - - function extend (a, b) { - for (var key in b) { - if (b.hasOwnProperty(key)) { - a[key] = b[key]; - } - } - return a; - } - - - function scrollReveal(options) { - this.options = extend(this.defaults, options); - this._init(); - } - - - - scrollReveal.prototype = { - defaults: { - axis: 'y', - distance: '25px', - duration: '0.66s', - delay: '0s', - - // if 0, the element is considered in the viewport as soon as it enters - // if 1, the element is considered in the viewport when it's fully visible - viewportFactor: 0.33 - }, - - /*=============================================================================*/ - - _init: function () { - - var self = this; - - this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); - this.scrolled = false; - - // Initialize all scrollreveals, triggering all - // reveals on visible elements. - this.elems.forEach(function (el, i) { - self.animate(el); - }); - - var scrollHandler = function () { - if (!self.scrolled) { - self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); - } - }; - - var resizeHandler = function () { - function delayed() { - self._scrollPage(); - self.resizeTimeout = null; - } - if (self.resizeTimeout) { - clearTimeout(self.resizeTimeout); - } - self.resizeTimeout = setTimeout(delayed, 200); - }; - - window.addEventListener('scroll', scrollHandler, false); - window.addEventListener('resize', resizeHandler, false); - }, - - /*=============================================================================*/ - - _scrollPage: function () { - var self = this; - - this.elems.forEach(function (el, i) { - if (isElementInViewport(el, self.options.viewportFactor)) { - self.animate(el); - } - }); - this.scrolled = false; - }, - - /*=============================================================================*/ - - parseLanguage: function (el) { - - // Splits on a sequence of one or more commas, periods or spaces. - var words = el.getAttribute('data-scrollreveal').split(/[,. ]+/), - enterFrom, - parsed = {}; - - function filter (words) { - var ret = [], - - blacklist = [ - "from", - "the", - "and", - "then", - "but" - ]; - - words.forEach(function (word, i) { - if (blacklist.indexOf(word) > -1) { - return; - } - ret.push(word); - }); - - return ret; - } - - words = filter(words); - - words.forEach(function (word, i) { - - switch (word) { - case "enter": - enterFrom = words[i + 1]; - - if (enterFrom == "top" || enterFrom == "bottom") { - parsed.axis = "y"; - } - - if (enterFrom == "left" || enterFrom == "right") { - parsed.axis = "x"; - } - - break; - - case "after": - parsed.delay = words[i + 1]; - break; - - case "wait": - parsed.delay = words[i + 1]; - break; - - case "move": - parsed.distance = words[i + 1]; - break; - - case "over": - parsed.duration = words[i + 1]; - break; - - case "trigger": - parsed.eventName = words[i + 1]; - break; - - default: - // Unrecognizable words; do nothing. - break; - } - }); - - // After all values are parsed, let’s make sure our our - // pixel distance is negative for top and left entrances. - // - // ie. "move 25px from top" starts at 'top: -25px' in CSS. - - if (enterFrom == "top" || enterFrom == "left") { - - if (!typeof parsed.distance == "undefined") { - parsed.distance = "-" + parsed.distance; - } - - else { - parsed.distance = "-" + this.options.distance; - } - - } - - return parsed; - }, - - /*=============================================================================*/ - - genCSS: function (el, axis) { - var parsed = this.parseLanguage(el); - - var dist = parsed.distance || this.options.distance, - dur = parsed.duration || this.options.duration, - delay = parsed.delay || this.options.delay, - axis = parsed.axis || this.options.axis; - - var transition = "-webkit-transition: all " + dur + " ease " + delay + ";" + - "-moz-transition: all " + dur + " ease " + delay + ";" + - "-o-transition: all " + dur + " ease " + delay + ";" + - "transition: all " + dur + " ease " + delay + ";"; - - var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + - "-moz-transform: translate" + axis + "(" + dist + ");" + - "transform: translate" + axis + "(" + dist + ");" + - "opacity: 0;"; - - var target = "-webkit-transform: translate" + axis + "(0);" + - "-moz-transform: translate" + axis + "(0);" + - "transform: translate" + axis + "(0);" + - "opacity: 1;"; - return { - transition: transition, - initial: initial, - target: target, - totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) - }; - }, - - /*=============================================================================*/ - - animate: function (el) { - var css = this.genCSS(el); - - if (!el.getAttribute('data-sr-init')) { - el.setAttribute('style', css.initial); - el.setAttribute('data-sr-init', true); - } - - if (isElementInViewport(el, this.options.viewportFactor)) { - el.setAttribute('style', css.target + css.transition); - - setTimeout(function () { - el.removeAttribute('style'); - }, css.totalDuration); - } - - }// end animate() - }; // end scrollReveal.prototype - - document.addEventListener("DOMContentLoaded", function (evt) { - window.scrollReveal = new scrollReveal(); - }); - -})(window); \ No newline at end of file From 8cb747f3598cc857b92dd3017caa034938565f42 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Mon, 20 Jan 2014 01:48:27 -0800 Subject: [PATCH 07/79] scrollReveal.js initial commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f15543a6..89213228 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ #scrollReveal.js -####Declarative CSS3 transitions on scroll. +####Declarative on-scroll reveal animations. A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) > **Disclaimer:** Please bare in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. From d3f9527ff893196de1a7ecb9e2ded517804670c6 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Mon, 20 Jan 2014 02:19:31 -0800 Subject: [PATCH 08/79] scrollReveal.js initial commit --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 89213228..16a0044a 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,14 @@ I noticed a growing number of clients were requesting on-scroll CSS3 transitions Many thanks to [@Codrops](https://twitter.com/codrops), [@Mary Lou](https://twitter.com/crnacura) and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, [Codrops](http://tympanus.net/codrops/). -© 2014 [@JulianLloyd](https://twitter.com/julianlloyd)
-Licensed under the MIT license. -[http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) +### 4. License + +Licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php) + +Copyright © 2014 © 2014 [@JulianLloyd](https://twitter.com/julianlloyd) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 98c794e4e9539c3e09bb33432a54d750fe52161f Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 22 Jan 2014 11:53:22 -0800 Subject: [PATCH 09/79] scrollReveal.js initial commit --- README.md | 4 +++- js/scrollReveal.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 16a0044a..2f9978f9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ #scrollReveal.js ####Declarative on-scroll reveal animations. A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) - +*** +#(See Demo)[http://julianlloyd.me/scrollreveal] +*** > **Disclaimer:** Please bare in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. ##1. Installation diff --git a/js/scrollReveal.js b/js/scrollReveal.js index b7c1e750..0f5f21ee 100644 --- a/js/scrollReveal.js +++ b/js/scrollReveal.js @@ -149,7 +149,7 @@ parseLanguage: function (el) { - // Splits on a sequence of one or more commas, periods or spaces. + // Splits on a sequence of one or more commas or spaces. var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), enterFrom, parsed = {}; From 9bf4e76f8fd556299d8b3f161980a34b1c885d3e Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 22 Jan 2014 11:54:08 -0800 Subject: [PATCH 10/79] scrollReveal.js initial commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f9978f9..e8c6ea10 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ####Declarative on-scroll reveal animations. A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) *** -#(See Demo)[http://julianlloyd.me/scrollreveal] +##[See Demo](http://julianlloyd.me/scrollreveal) *** > **Disclaimer:** Please bare in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. From 90ac74f9122929d12a131da11f0b7733d7aaef9c Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 22 Jan 2014 12:01:36 -0800 Subject: [PATCH 11/79] scrollReveal.js initial commit --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e8c6ea10..a61eba52 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) *** ##[See Demo](http://julianlloyd.me/scrollreveal) -*** > **Disclaimer:** Please bare in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. ##1. Installation From 1ab57c73eadc366a172c3a6f61fe62e62bb65627 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 22 Jan 2014 12:05:34 -0800 Subject: [PATCH 12/79] Update README and add LICENSE file --- LICENSE.txt | 21 +++++++++++++++++++++ README.md | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..e38ee5d2 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2014 Julian Lloyd https://twitter.com/julianlloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index a61eba52..635c155c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) *** ##[See Demo](http://julianlloyd.me/scrollreveal) -> **Disclaimer:** Please bare in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. +> **Disclaimer:** Please bear in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. ##1. Installation Clone or download download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate ready-to-go when the `DOMContentReady` event fires. From c3356148b6d6ef8641a32543d16b4739b12e5d27 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 22 Jan 2014 15:32:56 -0800 Subject: [PATCH 13/79] scrollReveal.js initial commit --- index.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 05d920f0..0f74211e 100644 --- a/index.html +++ b/index.html @@ -124,7 +124,6 @@

scrollReveal.js

- From ddc38e5eab7e2d057ad9b34e33f1eeee8f4ff577 Mon Sep 17 00:00:00 2001 From: Zachary Friedman Date: Wed, 22 Jan 2014 17:26:11 -0800 Subject: [PATCH 14/79] add support for bower --- bower.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 00000000..f04d2bfb --- /dev/null +++ b/bower.json @@ -0,0 +1,22 @@ +{ + "name": "scrollReveal.js", + "version": "0.0.0", + "homepage": "https://github.com/julianlloyd/scrollReveal.js", + "authors": [ + "Julian Lloyd " + ], + "description": "A simple way to create and maintain how elements fade in, triggered when they enter the viewport.", + "main": ["js/scrollReveal.js", "css/style.css"], + "keywords": [ + "animation" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "app/bower_components", + "test", + "tests" + ] +} From be831bba95b2521abd56dcf357444028fc01a987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20W=C3=B6lflein?= Date: Fri, 24 Jan 2014 17:48:51 +0100 Subject: [PATCH 15/79] Remove second "download" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 635c155c..adc0fe69 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A simple way to create and maintain how elements fade in, triggered when they en > **Disclaimer:** Please bear in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. ##1. Installation -Clone or download download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate ready-to-go when the `DOMContentReady` event fires. +Clone or download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate ready-to-go when the `DOMContentReady` event fires. ``` From 768efe0afc822b1e07e5209f6f99212999b309ca Mon Sep 17 00:00:00 2001 From: Mark IJbema Date: Sat, 25 Jan 2014 15:11:53 +0100 Subject: [PATCH 16/79] Added syntax highlighting to readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index adc0fe69..1b7d6b36 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ Clone or download `scrollReveal.js` into your JavaScript folder, and reference i ##2. Usage By adding a `data-scrollreveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport.

**Fig 1**: -``` +```html

Hello world!

``` However, scrollReveal.js allows you to define custom reveal behavior, using *descriptive language*.

**Fig 2**: -``` +```html

Foo

Bar

@@ -75,7 +75,7 @@ While **keywords** must be followed by an appropriate accepted **value**, the us - `but` **Fig 3**: -``` +```html
Example 1
Example 1
From cd6cdfcdc46e44ac9dcdae53f12c026e2c65be89 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Sat, 25 Jan 2014 13:22:38 -0800 Subject: [PATCH 17/79] Remove duplicate copyright --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b7d6b36..aacc753f 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Many thanks to [@Codrops](https://twitter.com/codrops), [@Mary Lou](https://twit Licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php) -Copyright © 2014 © 2014 [@JulianLloyd](https://twitter.com/julianlloyd) +Copyright © 2014 [@JulianLloyd](https://twitter.com/julianlloyd) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 7cb63b6cf95c2a31524d67d17d2c93ad532f79a7 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Sun, 26 Jan 2014 19:30:21 -0800 Subject: [PATCH 18/79] Update anchor styles, resolve #9 --- css/style.css | 8 ++++---- index.html | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/css/style.css b/css/style.css index 1798e6bc..9f99f459 100644 --- a/css/style.css +++ b/css/style.css @@ -132,16 +132,16 @@ p { margin: 0.33em 0; } -a:link, -a:visited { +a.inline:link, +a.inline:visited { color: #35ff99; text-decoration: none; border-radius: 5px; padding: 2px; } -a:hover, -a:active { +a.inline:hover, +a.inline:active { background: #35ff99; color: #202a39; } diff --git a/index.html b/index.html index 0f74211e..0bf33713 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@

scrollReveal.js

Declarative on-scroll reveal animations.

-

An open-source project by @JulianLloyd

+

An open-source project by @JulianLloyd

From 6a23a70ac9606733ecac9ee40376c46fc0e43d56 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Sun, 26 Jan 2014 19:50:58 -0800 Subject: [PATCH 19/79] Update README --- README.md | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index aacc753f..cb67b0d4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A simple way to create and maintain how elements fade in, triggered when they en Clone or download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate ready-to-go when the `DOMContentReady` event fires. -``` +```html // Everything else // ... @@ -17,22 +17,20 @@ Clone or download `scrollReveal.js` into your JavaScript folder, and reference i ``` ->**NOTE:** scrollReveal.js does not require jQuery, but *does* rely upon CSS3 transitions; it has been developed exclusively for modern browser use only. +>**NOTE:** scrollReveal.js does not require jQuery, but *does* rely upon CSS3 transitions; as such, it has been developed exclusively for modern browser use only. ##2. Usage By adding a `data-scrollreveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport.

**Fig 1**: ```html -

Hello world!

+

Hello world!

``` -However, scrollReveal.js allows you to define custom reveal behavior, using *descriptive language*.

**Fig 2**: +However, scrollReveal.js allows you to define custom reveals, using *descriptive language*.

**Fig 2**: ```html -

Foo

- +

Foo

Bar

- - +

Baz

``` @@ -46,22 +44,30 @@ These words describe the reveal behavior, using **keyword** / **value** pairs. --- - **Enter** — Controls the direction of your element transition. Whatever value is passed is considered the vector origin. For example, specifying `top` will reveal your element with a downward motion. - * Accepted value: `top`, `right`, `bottom` or `left` → (eg. `enter top`) + + * Accepted values: `top`, `right`, `bottom` or `left` + * Example: `enter top` --- - **Move** — The distance your element will travel during transition. - * Accepted value: **[ integer ] px** → (eg. `move 33px`) + + * Accepted value: **[ integer ] px** + * Example: `move 33px` --- - **Over** — The duration of your element’s transition. - * Accepted value: **[ decimal ] s** → (eg. `over 1.66s`) + + * Accepted value: **[ decimal ] s** + * Example: `over 1.66s` --- - **After/Wait** — The delay before your element beings its transition. - * Accepted value: **[ decimal ] s** → (eg. `after 0.33s` or `wait 0.33s`) + + * Accepted value: **[ decimal ] s** + * Example: `after 0.33s` or `wait 0.33s` --- @@ -77,17 +83,17 @@ While **keywords** must be followed by an appropriate accepted **value**, the us **Fig 3**: ```html -
Example 1
-
Example 1
+

foo

+

foo

-
Example 2
-
Example 2
-
Example 2
+

bar

+

bar

+

bar

``` -### 3. Contributions / Thanks! -I noticed a growing number of clients were requesting on-scroll CSS3 transitions for various site elements, and so scrollReveal.js was made to help with development. If you’d like to contribute—please do! +### 3. Contributions +There are already some great ideas under development (see [open issues](https://github.com/julianlloyd/scrollReveal.js/issues?state=open)); if you’d like to contribute, please do! Many thanks to [@Codrops](https://twitter.com/codrops), [@Mary Lou](https://twitter.com/crnacura) and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, [Codrops](http://tympanus.net/codrops/). @@ -95,7 +101,7 @@ Many thanks to [@Codrops](https://twitter.com/codrops), [@Mary Lou](https://twit Licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php) -Copyright © 2014 [@JulianLloyd](https://twitter.com/julianlloyd) +Copyright 2014 [@JulianLloyd](https://twitter.com/julianlloyd) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 59548f709484d229d917945eac688bfe4dc7498a Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Sun, 26 Jan 2014 23:56:50 -0800 Subject: [PATCH 20/79] Fix typo in README section 2.1.1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb67b0d4..0457fe02 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ These words describe the reveal behavior, using **keyword** / **value** pairs. --- -- **After/Wait** — The delay before your element beings its transition. +- **After/Wait** — The delay before your element begins its transition. * Accepted value: **[ decimal ] s** * Example: `after 0.33s` or `wait 0.33s` From f912056a2bb949eee0aff3c723c2c01da648f62d Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Mon, 27 Jan 2014 01:28:27 -0800 Subject: [PATCH 21/79] Minor cleanup for Bower support --- bower.json | 9 ++++++--- js/scrollReveal.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index f04d2bfb..52a375df 100644 --- a/bower.json +++ b/bower.json @@ -1,14 +1,17 @@ { "name": "scrollReveal.js", - "version": "0.0.0", + "version": "0.0.1", "homepage": "https://github.com/julianlloyd/scrollReveal.js", "authors": [ "Julian Lloyd " ], "description": "A simple way to create and maintain how elements fade in, triggered when they enter the viewport.", - "main": ["js/scrollReveal.js", "css/style.css"], + "main": ["js/scrollReveal.js"], "keywords": [ - "animation" + "animation", + "CSS", + "transition", + "JavaScript" ], "license": "MIT", "ignore": [ diff --git a/js/scrollReveal.js b/js/scrollReveal.js index 0f5f21ee..10286531 100644 --- a/js/scrollReveal.js +++ b/js/scrollReveal.js @@ -241,7 +241,7 @@ /*=============================================================================*/ - genCSS: function (el, axis) { + genCSS: function (el) { var parsed = this.parseLanguage(el); var dist = parsed.distance || this.options.distance, From a1fa2271e8a584a469941f76ea481f4362078c8f Mon Sep 17 00:00:00 2001 From: Alexandra Hoefinger Date: Wed, 5 Feb 2014 11:05:39 -0500 Subject: [PATCH 22/79] Update style.css fixed typo in line 70. killer project! --- css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index 9f99f459..db1bae62 100644 --- a/css/style.css +++ b/css/style.css @@ -67,7 +67,7 @@ html { } h1, .h1 { - font-family: "proxima-nova", sams-serif; + font-family: "proxima-nova", sans-serif; font-weight: 100; } From 6250b11e71e8c2c1c87ff14b2918a375b40b2d2d Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 02:09:44 -0800 Subject: [PATCH 23/79] add support for animation reset, easing and manual initialization --- CHANGELOG.md | 0 LICENSE.md | 12 ++ LICENSE.txt | 21 --- README.md | 256 ++++++++++++++++++++++++-------- css/style.css | 322 ---------------------------------------- index.html | 166 --------------------- js/scrollReveal.js | 304 -------------------------------------- scrollReveal.js | 359 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 566 insertions(+), 874 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md delete mode 100644 LICENSE.txt delete mode 100644 css/style.css delete mode 100644 index.html delete mode 100644 js/scrollReveal.js create mode 100644 scrollReveal.js diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..92673a9f --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,12 @@ +License +------- + +The MIT License (MIT) + +Copyright © 2014 [Julian Lloyd](https://twitter.com/julianlloyd) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index e38ee5d2..00000000 --- a/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (c) 2014 Julian Lloyd https://twitter.com/julianlloyd - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 0457fe02..2d5f02a5 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,244 @@ #scrollReveal.js -####Declarative on-scroll reveal animations. -A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment by [@JulianLloyd](https://twitter.com/julianlloyd) +A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment from [@JulianLloyd](https://twitter.com/julianlloyd). + +[![scrollReveal version](https://badge.fury.io/gh/julianlloyd%2FscrollReveal.js.png)](http://badge.fury.io/gh/julianlloyd%2FscrollReveal.js) [![Bitdeli Analytics](https://d2weczhvl823v0.cloudfront.net/julianlloyd/scrollreveal.js/trend.png)](https://bitdeli.com/free) +*** +####**[→ View Demo ←](http://julianlloyd.me/scrollreveal)** *** -##[See Demo](http://julianlloyd.me/scrollreveal) -> **Disclaimer:** Please bear in mind that this plug-in is an experimental stage, and that breaking changes are virtually guaranteed in future updates. +Installation +------------ +> **Disclaimer:** scrollReveal.js is in early development, and breaking changes will likely occur in future updates. Before updating, please refer to the [CHANGELOG](https://github.com/julianlloyd/scrollReveal.js/blob/master/README.md) for details. -##1. Installation -Clone or download `scrollReveal.js` into your JavaScript folder, and reference it just before the closing `` tag. It will automatically instantiate ready-to-go when the `DOMContentReady` event fires. +##### Download +[scrollReveal.js ](https://github.com/julianlloyd/scrollReveal.js/archive/master.zip) + +##### GitHub +`git clone https://github.com/julianlloyd/scrollReveal.js.git` + +##### Bower +`bower install scrollReveal.js` + +*** +Once you have a copy of `scrollReveal.js`, place it in your JavaScript folder, and include the following JavaScript just before the closing `` tag. ```html - // Everything else - // ... + + + + + window.scrollReveal = new scrollReveal(); + + ``` +Basic Usage +----------- +By adding a `data-scrollReveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport: +```html + +
Hello world!
+``` +**But wait!** It’s more fun if you define your own reveal animation parameters, which you can do using using natural, declarative language: +```html + +
Foo
+
Bar
+
Baz
+``` ->**NOTE:** scrollReveal.js does not require jQuery, but *does* rely upon CSS3 transitions; as such, it has been developed exclusively for modern browser use only. +Getting Started +--------------- +What you enter into the `data-scrollReveal` attribute is parsed for specific words: +- **keywords** that expect to be followed by a **value**.

+- **fillers** as natural language sugar. (optional) -##2. Usage -By adding a `data-scrollreveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport.

**Fig 1**: +##### Keywords and Values +These specific **keyword** / **value** pairs allow you to describe basic reveal animation behavior. +*** +**keyword:** `enter` — Controls the vector origin of your reveal animation. +**value:** `top` | `right` | `bottom` | `left`

+*Example:* +```html + +
Foo
+``` +*** +**keyword:** `move` — The distance your revealing element travels. +**value:** [ integer ]px. +*Example:* ```html -

Hello world!

+
Bar
``` -However, scrollReveal.js allows you to define custom reveals, using *descriptive language*.

**Fig 2**: +*** +**keyword:** `over` — The duration of your reveal animation. +**value:** [ decimal ]s + + +*Example:* ```html -

Foo

-

Bar

-

Baz

+
Baz
``` +*** +**keyword:** `after/wait` — The duration before your reveal begins. +**value:** [ decimal ]s +*Example:* +```html + +
Mel
+
Mel
+``` -###2.1 Keywords, Values and Fillers -Whatever string is passed to the `data-scrollreveal` attribute is parsed for specific words: **keywords** that expect to be followed by a **value**, and semantic **fillers** that facilitate more natural language. +#####Combining Keyword/Value Pairs +You can easily combine the above pairs to create more dynamic reveal animations. -####2.1.1 Keywords and Values -These words describe the reveal behavior, using **keyword** / **value** pairs. +*Example:* +```html +
Foo
+
Bar
+
Baz
+
Mel
+``` ---- +##### Fillers (optional) +You can use conjoining filler words for more readable language. -- **Enter** — Controls the direction of your element transition. Whatever value is passed is considered the vector origin. For example, specifying `top` will reveal your element with a downward motion. +- `from` +- `the` +- `and` +- `then` +- `but` +- `with` +- `,` - * Accepted values: `top`, `right`, `bottom` or `left` - * Example: `enter top` +*Example*: +```html + +
Foo
+
Bar
+
Baz
+
Mel
---- +``` +Advanced Usage +-------------- +#####Custom defaults +You can pass an object to the constructor with your desired default configuration. +```html + + +``` +By default `init` is set to `true`, meaning `scrollReveal.init()` fires on instantiation. (This registers DOM elements and prepares them to reveal)

You may want to set `init` to `false` if you’re working with templates or other generated content, letting you control when `scrollReveal.init()` is first called.

You can also call this method any time afterwards to re-check all elements in the DOM with `data-scrollReveal` for attributes. -- **Move** — The distance your element will travel during transition. +##### Generated HTML +You may have dynamically generated HTML in your use case, (AJAX, templates, other JavaScript libraries, etc.,) so as mentioned above, the scrollReveal object has the `init()` helper method that checks for new elements in the DOM. - * Accepted value: **[ integer ] px** - * Example: `move 33px` +*Example:* +```html + ---- + + + +``` -#### 2.1.2 Fillers -While **keywords** must be followed by an appropriate accepted **value**, the use of conjoining **fillers** are permitted for more readable language. These are shown below: -- `from` -- `the` -- `and` -- `then` -- `but` +##### Viewport Factor +If set to **0**, the element is considered in the viewport as soon as it enters.
+If set to **1**, the element is considered in the viewport when it is fully visible. + +*Example:* +```javascript + var config = { + viewportFactor: 0.33 + }; + + // Your reveal animation triggers after 33% of + // your element is visible within the viewport. +``` -**Fig 3**: +##### Replaying animations +**Keyword:** `reset` — replay reveal animations every time elements enter the viewport. ```html - -

foo

-

foo

- - -

bar

-

bar

-

bar

+ +
Foo
``` +> ***Important Note:** scrollReveal by defaut does not reset reveal animations, and will remove the appended `style` attribute (containing generated CSS) from your elements.

However, to prevent flickering in reveal animations when using the keyword `reset`, scrollReveal does not remove the this appended `style` attribute.

This means using the `reset` keyword may cause the scrollReveal animation CSS properties to override or conflict with any other CSS transform and transition properties on that element. -### 3. Contributions -There are already some great ideas under development (see [open issues](https://github.com/julianlloyd/scrollReveal.js/issues?state=open)); if you’d like to contribute, please do! +##### Controlling Easing +The `move` keyword can be replaced with any one of the following:

+- `ease-in` +- `ease-out` +- `ease-in-out` -Many thanks to [@Codrops](https://twitter.com/codrops), [@Mary Lou](https://twitter.com/crnacura) and the [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/), © 2014, [Codrops](http://tympanus.net/codrops/). +*Example:* +```html +
Foo
+``` + +Browser Support +--------------- +scrollReveal.js does not require jQuery, but does rely on [CSS3 transitions](http://caniuse.com/#search=transition) to power its reveal animations; it has been developed exclusively for **modern browser use only**. + +Contributions +------------- +Community feedback and involvement is highly encouraged. +*** +#### [→ Open Issues ←](https://github.com/julianlloyd/scrollReveal.js/issues?state=open) +*** +##### Special Thanks +scrollReveal.js was inspired by the awesome [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/) by [Mary Lou](https://twitter.com/crnacura). Copyright © 2014 [Codrops](http://tympanus.net/codrops/). -### 4. License +License +------- -Licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php) +The MIT License (MIT) -Copyright 2014 [@JulianLloyd](https://twitter.com/julianlloyd) +Copyright © 2014 [Julian Lloyd](https://twitter.com/julianlloyd) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/css/style.css b/css/style.css deleted file mode 100644 index db1bae62..00000000 --- a/css/style.css +++ /dev/null @@ -1,322 +0,0 @@ -/* http://meyerweb.com/eric/tools/css/reset/ - v2.0 | 20110126 - License: none (public domain) -*/ -html, body, div, span, applet, object, iframe, -h1, h2, h3, h4, h5, h6, p, blockquote, pre, -a, abbr, acronym, address, big, cite, code, -del, dfn, em, img, ins, kbd, q, s, samp, -small, strike, strong, sub, sup, tt, var, -b, u, i, center, -dl, dt, dd, ol, ul, li, -fieldset, form, label, legend, -table, caption, tbody, tfoot, thead, tr, th, td, -article, aside, canvas, details, embed, -figure, figcaption, footer, header, hgroup, -menu, nav, output, ruby, section, summary, -time, mark, audio, video { - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - font: inherit; - vertical-align: baseline; -} - -/* HTML5 display-role reset for older browsers */ -article, aside, details, figcaption, figure, -footer, header, hgroup, menu, nav, section { - display: block; -} - -body { - line-height: 1; -} - -ol, ul { - list-style: none; -} - -blockquote, q { - quotes: none; -} - -blockquote:before, blockquote:after, -q:before, q:after { - content: ''; - content: none; -} - -table { - border-collapse: collapse; - border-spacing: 0; -} - -a { - cursor: pointer; -} - -* { - -moz-box-sizing: border-box; - box-sizing: border-box; -} - -html { - overflow: -moz-scrollbars-vertical; - overflow-y: scroll; -} - -h1, .h1 { - font-family: "proxima-nova", sans-serif; - font-weight: 100; -} - -html, body { - font-family: "proxima-nova", sans-serif; - font-weight: 300; -} - -.clearfix:before, -.clearfix:after { - content: " "; - display: table; -} - -.clearfix:after { - clear: both; -} - -html, body { - color: white; - text-align: center; -} -@media screen and (min-width: 300px) { - html, body { - font-size: 14px; - } -} -@media screen and (min-width: 460px) { - html, body { - font-size: 20px; - } -} -@media screen and (min-width: 900px) { - html, body { - font-size: 24px; - } -} - -h1, .h1 { - line-height: 1.166; - margin: .66em 0; -} - -@media screen and (min-width: 300px) { - h1, .h1 { - font-size: 2.33em; - } -} -@media screen and (min-width: 460px) { - h1, .h1 { - font-size: 2.66em; - } -} -@media screen and (min-width: 720px) { - h1, .h1 { - font-size: 3.33em; - } -} - -p { - color: #616c84; - margin: 0.33em 0; -} - -a.inline:link, -a.inline:visited { - color: #35ff99; - text-decoration: none; - border-radius: 5px; - padding: 2px; -} - -a.inline:hover, -a.inline:active { - background: #35ff99; - color: #202a39; -} - -small { - font-size: .75em; -} - -em { - font-style: italic; -} - -.text-left { - text-align: left; -} - -.text-right { - text-align: right; -} - -.text-center { - text-align: center; -} - -html, body { - height: 100%; - background: #202a39; -} - -.column-container { - width: 80%; - max-width: 1000px; - margin: 0 auto; - overflow: hidden; - height: 250%; - text-align: center; -} -@media screen and (min-width: 300px) { - .column-container { - padding-top: 20%; - margin-bottom: -125px; - } -} -@media screen and (min-width: 720px) { - .column-container { - padding-top: 10%; - } -} - -.column { - width: 3%; - height: 100%; - margin: 0 2%; - display: inline-block; -} - -.block { - border-radius: 5px; - margin-bottom: 150%; -} - -.block-1x { - height: 10%; -} - -.block-2x { - height: 15%; -} - -.block-3x { - height: 20%; -} - -.block-blueberry { - background: #008597; -} - -.block-slate { - background: #2d3443; -} - -.block-grape { - background: #4d407c; -} - -.block-raspberry { - background: #ff005d; -} - -.block-mango { - background: #ffcc00; -} - -.block-orange { - background: #ff7c35; -} - -.block-kiwi { - background: #35ff99; -} - -.withLove { - overflow: hidden; - text-align: center; - padding-bottom: 2em; - cursor: default; - color: #616c84; -} -@media screen and (min-width: 900px) { - .withLove { - margin-top: 125px; - } -} -.withLove * { - display: inline-block; -} -.withLove .alpha, -.withLove .omega { - width: 40%; -} -.withLove .alpha { - text-align: right; -} -.withLove .omega { - text-align: left; -} -.withLove .heart { - margin: 0 -2px; - position: relative; - z-index: 3; - -webkit-animation: throb 1.33s ease-in-out infinite; - animation: throb 1.33s ease-in-out infinite; -} -.withLove .heart path { - fill: #ff005d; -} -@media screen and (min-width: 300px) { - .withLove .heart { - width: 30px; - height: 30px; - top: .66em; - } -} -@media screen and (min-width: 460px) { - .withLove .heart { - top: .8em; - width: 50px; - height: 50px; - } -} - -@-webkit-keyframes throb { - 0% { - -webkit-transform: scale(1); - } - - 50% { - -webkit-transform: scale(0.8); - } - - 100% { - -webkit-transform: scale(1); - } -} - -@keyframes throb { - 0% { - transform: scale(1); - } - - 50% { - transform: scale(0.8); - } - - 100% { - transform: scale(1); - } -} diff --git a/index.html b/index.html deleted file mode 100644 index 0bf33713..00000000 --- a/index.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - scrollReveal.js - - - - - - - - - - - - - - - - - - Fork me on GitHub - - -

scrollReveal.js

-

Declarative on-scroll reveal animations.

-

An open-source project by @JulianLloyd

- -
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
- -
- -
- Made with - - - - - - - - in California -
- - - - - - \ No newline at end of file diff --git a/js/scrollReveal.js b/js/scrollReveal.js deleted file mode 100644 index 10286531..00000000 --- a/js/scrollReveal.js +++ /dev/null @@ -1,304 +0,0 @@ -/* - _ _ _____ _ _ - | | | __ \ | | (_) - ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ - / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| - \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ - _/ | - |__/ - - "Declarative on-scroll reveal animations." - -/*============================================================================= - - scrollReveal.js is inspired by cbpScroller.js, © 2014, Codrops. - - Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php - - scrollReveal.js, © 2014 https://twitter.com/julianlloyd - -=============================================================================*/ - -;(function (window) { - - 'use strict'; - - var docElem = window.document.documentElement; - - function getViewportH () { - var client = docElem['clientHeight'], - inner = window['innerHeight']; - - return (client < inner) ? inner : client; - } - - function getOffset (el) { - var offsetTop = 0, - offsetLeft = 0; - - do { - if (!isNaN(el.offsetTop)) { - offsetTop += el.offsetTop; - } - if (!isNaN(el.offsetLeft)) { - offsetLeft += el.offsetLeft; - } - } while (el = el.offsetParent) - - return { - top: offsetTop, - left: offsetLeft - } - } - - function isElementInViewport (el, h) { - var scrolled = window.pageYOffset, - viewed = scrolled + getViewportH(), - elH = el.offsetHeight, - elTop = getOffset(el).top, - elBottom = elTop + elH, - h = h || 0; - - return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - } - - function extend (a, b) { - for (var key in b) { - if (b.hasOwnProperty(key)) { - a[key] = b[key]; - } - } - return a; - } - - - function scrollReveal(options) { - this.options = extend(this.defaults, options); - this._init(); - } - - - - scrollReveal.prototype = { - defaults: { - axis: 'y', - distance: '25px', - duration: '0.66s', - delay: '0s', - - // if 0, the element is considered in the viewport as soon as it enters - // if 1, the element is considered in the viewport when it's fully visible - viewportFactor: 0.33 - }, - - /*=============================================================================*/ - - _init: function () { - - var self = this; - - this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); - this.scrolled = false; - - // Initialize all scrollreveals, triggering all - // reveals on visible elements. - this.elems.forEach(function (el, i) { - self.animate(el); - }); - - var scrollHandler = function () { - if (!self.scrolled) { - self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); - } - }; - - var resizeHandler = function () { - function delayed() { - self._scrollPage(); - self.resizeTimeout = null; - } - if (self.resizeTimeout) { - clearTimeout(self.resizeTimeout); - } - self.resizeTimeout = setTimeout(delayed, 200); - }; - - window.addEventListener('scroll', scrollHandler, false); - window.addEventListener('resize', resizeHandler, false); - }, - - /*=============================================================================*/ - - _scrollPage: function () { - var self = this; - - this.elems.forEach(function (el, i) { - if (isElementInViewport(el, self.options.viewportFactor)) { - self.animate(el); - } - }); - this.scrolled = false; - }, - - /*=============================================================================*/ - - parseLanguage: function (el) { - - // Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), - enterFrom, - parsed = {}; - - function filter (words) { - var ret = [], - - blacklist = [ - "from", - "the", - "and", - "then", - "but" - ]; - - words.forEach(function (word, i) { - if (blacklist.indexOf(word) > -1) { - return; - } - ret.push(word); - }); - - return ret; - } - - words = filter(words); - - words.forEach(function (word, i) { - - switch (word) { - case "enter": - enterFrom = words[i + 1]; - - if (enterFrom == "top" || enterFrom == "bottom") { - parsed.axis = "y"; - } - - if (enterFrom == "left" || enterFrom == "right") { - parsed.axis = "x"; - } - - return; - - case "after": - parsed.delay = words[i + 1]; - return; - - case "wait": - parsed.delay = words[i + 1]; - return; - - case "move": - parsed.distance = words[i + 1]; - return; - - case "over": - parsed.duration = words[i + 1]; - return; - - case "trigger": - parsed.eventName = words[i + 1]; - return; - - default: - // Unrecognizable words; do nothing. - return; - } - }); - - // After all values are parsed, let’s make sure our our - // pixel distance is negative for top and left entrances. - // - // ie. "move 25px from top" starts at 'top: -25px' in CSS. - - if (enterFrom == "top" || enterFrom == "left") { - - if (!typeof parsed.distance == "undefined") { - parsed.distance = "-" + parsed.distance; - } - - else { - parsed.distance = "-" + this.options.distance; - } - - } - - return parsed; - }, - - /*=============================================================================*/ - - genCSS: function (el) { - var parsed = this.parseLanguage(el); - - var dist = parsed.distance || this.options.distance, - dur = parsed.duration || this.options.duration, - delay = parsed.delay || this.options.delay, - axis = parsed.axis || this.options.axis; - - var transition = "-webkit-transition: all " + dur + " ease " + delay + ";" + - "-moz-transition: all " + dur + " ease " + delay + ";" + - "-o-transition: all " + dur + " ease " + delay + ";" + - "transition: all " + dur + " ease " + delay + ";"; - - var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + - "-moz-transform: translate" + axis + "(" + dist + ");" + - "transform: translate" + axis + "(" + dist + ");" + - "opacity: 0;"; - - var target = "-webkit-transform: translate" + axis + "(0);" + - "-moz-transform: translate" + axis + "(0);" + - "transform: translate" + axis + "(0);" + - "opacity: 1;"; - return { - transition: transition, - initial: initial, - target: target, - totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) - }; - }, - - /*=============================================================================*/ - - animate: function (el) { - var css = this.genCSS(el); - - if (!el.getAttribute('data-sr-init')) { - el.setAttribute('style', css.initial); - el.setAttribute('data-sr-init', true); - } - - if (el.getAttribute('data-sr-complete')) { - return; - } - - if (isElementInViewport(el, this.options.viewportFactor)) { - el.setAttribute('style', css.target + css.transition); - - setTimeout(function () { - el.removeAttribute('style'); - el.setAttribute('data-sr-complete', true); - }, css.totalDuration); - } - - } - }; // end scrollReveal.prototype - - document.addEventListener("DOMContentLoaded", function (evt) { - window.scrollReveal = new scrollReveal(); - }); - -})(window); \ No newline at end of file diff --git a/scrollReveal.js b/scrollReveal.js new file mode 100644 index 00000000..b64b5710 --- /dev/null +++ b/scrollReveal.js @@ -0,0 +1,359 @@ +/* + _ _ _____ _ _ + | | | __ \ | | (_) + ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ + / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| + \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.0.2 + _/ | + |__/ + + "Declarative on-scroll reveal animations." + +/*============================================================================= + + scrollReveal.js was inspired by cbpScroller.js (c) 2014 Codrops. + + Licensed under the MIT license. + http://www.opensource.org/licenses/mit-license.php + + scrollReveal.js (c) 2014 Julian Lloyd + +=============================================================================*/ + +window.scrollReveal = (function (window) { + + 'use strict'; + + function scrollReveal(options) { + + this.docElem = window.document.documentElement; + this.options = this.extend(this.defaults, options); + this.self = this; + + if (this.options.init == true) this.init(); + } + + scrollReveal.prototype = { + + defaults: { + after: '0s', + enter: 'bottom', + move: '24px', + over: '0.66s', + easing: 'ease-in-out', + + // if 0, the element is considered in the viewport as soon as it enters + // if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33, + + // if false, animations occur only once + // if true, animations occur each time an element enters the viewport + reset: false, + + // if true, scrollReveal.init() is automaticaly called upon instantiation + init: true + }, + + /*=============================================================================*/ + + init: function () { + + this.scrolled = false; + + var self = this; + + // Check DOM for the data-scrollReveal attribute + // and initialize all found elements. + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scrollReveal]')); + this.elems.forEach(function (el, i) { + self.update(el); + }); + + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; + + var resizeHandler = function () { + + // If we’re still waiting for settimeout, reset the timer. + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + self.resizeTimeout = setTimeout(delayed, 200); + }; + + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, + + /*=============================================================================*/ + + _scrollPage: function () { + var self = this; + + this.elems.forEach(function (el, i) { + self.update(el); + }); + this.scrolled = false; + }, + + /*=============================================================================*/ + + parseLanguage: function (el) { + + // Splits on a sequence of one or more commas or spaces. + var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + parsed = {}; + + function filter (words) { + var ret = [], + + blacklist = [ + "from", + "the", + "and", + "then", + "but", + "with" + ]; + + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); + + return ret; + } + + words = filter(words); + + words.forEach(function (word, i) { + + switch (word) { + case "enter": + parsed.enter = words[i + 1]; + return; + + case "after": + parsed.after = words[i + 1]; + return; + + case "wait": + parsed.after = words[i + 1]; + return; + + case "move": + parsed.move = words[i + 1]; + return; + + case "ease": + parsed.move = words[i + 1]; + parsed.ease = "ease"; + return; + + case "ease-in": + parsed.move = words[i + 1]; + parsed.easing = "ease-in"; + return; + + case "ease-in-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-in-out"; + return; + + case "ease-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-out"; + return; + + case "over": + parsed.over = words[i + 1]; + return; + + case "trigger": + parsed.eventName = words[i + 1]; + return; + + default: + return; + } + }); + + return parsed; + }, + + + /*=============================================================================*/ + + update: function (el) { + var css = this.genCSS(el), + self = this; + + if (!el.getAttribute('data-scrollReveal-initialized')) { + el.setAttribute('style', css.initial); + el.setAttribute('data-scrollReveal-initialized', true); + } + + if (!this.isElementInViewport(el, this.options.viewportFactor)) { + if (this.options.reset) { + el.setAttribute('style', css.initial + css.reset); + } + return; + } + + if (this.isElementInViewport(el, this.options.viewportFactor)) { + if (!el.getAttribute('data-scrollReveal-completed')) { + el.setAttribute('style', css.target + css.transition); + } + // Without reset enabled, we can safely remove the style tag + // to prevent CSS specificy wars with authored CSS. + if (!this.options.reset) { + setTimeout(function () { + el.removeAttribute('style'); + el.setAttribute('data-scrollReveal-completed',true); + }, css.totalDuration); + } + return; + } + }, + + /*=============================================================================*/ + + genCSS: function (el) { + var parsed = this.parseLanguage(el), + enter, + axis; + + if (parsed.enter) { + + if (parsed.enter == "top" || parsed.enter == "bottom") { + enter = parsed.enter; + axis = "y"; + } + + if (parsed.enter == "left" || parsed.enter == "right") { + enter = parsed.enter; + axis = "x"; + } + + } else { + + if (this.options.enter == "top" || this.options.enter == "bottom") { + enter = this.options.enter + axis = "y"; + } + + if (this.options.enter == "left" || this.options.enter == "right") { + enter = this.options.enter + axis = "x"; + } + } + + // After all values are parsed, let’s make sure our our + // pixel distance is negative for top and left entrances. + // + // ie. "move 25px from top" starts at 'top: -25px' in CSS. + + if (enter == "top" || enter == "left") { + if (!typeof parsed.move == "undefined") { + parsed.move = "-" + parsed.move; + } + else { + parsed.move = "-" + this.options.move; + } + } + + var dist = parsed.move || this.options.move, + dur = parsed.over || this.options.over, + delay = parsed.after || this.options.after, + easing = parsed.easing || this.options.easing; + + var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + + "-moz-transition: all " + dur + " " + easing + " " + delay + ";" + + "-o-transition: all " + dur + " " + easing + " " + delay + ";" + + "transition: all " + dur + " " + easing + " " + delay + ";"; + + // The same as transition, but removing the delay for elements fading out. + var reset = "-webkit-transition: all " + dur + " " + easing + ";" + + "-moz-transition: all " + dur + " " + easing + ";" + + "-o-transition: all " + dur + " " + easing + ";" + + "transition: all " + dur + " " + easing + ";"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "-moz-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "-moz-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + getViewportH : function () { + var client = this.docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + }, + + getOffset : function(el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) + + return { + top: offsetTop, + left: offsetLeft + } + }, + + isElementInViewport : function(el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + this.getViewportH(), + elH = el.offsetHeight, + elTop = this.getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + }, + + extend: function (a, b){ + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; + } + }; // end scrollReveal.prototype + + return scrollReveal; +})(window); \ No newline at end of file From 32b80c55d96e8f996241f91e7de93dec3ee36e2d Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 02:29:18 -0800 Subject: [PATCH 24/79] update README and CHANGELOG --- CHANGELOG.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 26 ++++++++++----------- 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29b..88160b7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,64 @@ +#Changelog + +0.0.2 +----- + +### BREAKING CHANGES + +The `scrollreveal` attribute has changed to `scrollReveal` (updated with camel case). If you’re updating to scrollReveal v0.0.2, make sure your data-attributes are correctly renamed. + +#### Manual Instantiation +scrollReveal no longer automatically instantiates on the `DOMContentLoaded` event. It now requires that you instantiate it manually. + +```html + + + + +``` +#### Defaults Object + +You can now pass your own starting defaults object to the scrollReveal constructor. + +```html + +``` +#### Reply Your Animations +Due to popular demand, the `reset` keyword was added. Now, you can configure your animations to replay every time they enter the viewport: + +*example*: +```html + +``` + +>**See it in action:** The [demo page](http://julianlloyd.me/scrollreveal) has been updated with the `reset: true` +

+ +#### Easing Control +Now you can replace the `move` keyword with easing keywords to control the easing of your reveal animation. + +*example*: +```html +
Foo
+``` \ No newline at end of file diff --git a/README.md b/README.md index 2d5f02a5..307772fd 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,15 @@ A simple way to create and maintain how elements fade in, triggered when they en *** Installation ------------ -> **Disclaimer:** scrollReveal.js is in early development, and breaking changes will likely occur in future updates. Before updating, please refer to the [CHANGELOG](https://github.com/julianlloyd/scrollReveal.js/blob/master/README.md) for details. +> **Disclaimer:** scrollReveal.js is in early development, and breaking changes will likely occur in future updates. Before updating, please refer to the [CHANGELOG](https://github.com/julianlloyd/scrollReveal.js/blob/master/CHANGELOG.md) for details. -##### Download +#### Download [scrollReveal.js ](https://github.com/julianlloyd/scrollReveal.js/archive/master.zip) -##### GitHub +#### GitHub `git clone https://github.com/julianlloyd/scrollReveal.js.git` -##### Bower +#### Bower `bower install scrollReveal.js` *** @@ -55,7 +55,7 @@ What you enter into the `data-scrollReveal` attribute is parsed for specific wor - **keywords** that expect to be followed by a **value**.

- **fillers** as natural language sugar. (optional) -##### Keywords and Values +#### Keywords and Values These specific **keyword** / **value** pairs allow you to describe basic reveal animation behavior. *** **keyword:** `enter` — Controls the vector origin of your reveal animation. @@ -94,7 +94,7 @@ These specific **keyword** / **value** pairs allow you to describe basic reveal
Mel
``` -#####Combining Keyword/Value Pairs +####Combining Keyword/Value Pairs You can easily combine the above pairs to create more dynamic reveal animations. *Example:* @@ -105,7 +105,7 @@ You can easily combine the above pairs to create more dynamic reveal animations.
Mel
``` -##### Fillers (optional) +#### Fillers (optional) You can use conjoining filler words for more readable language. - `from` @@ -127,7 +127,7 @@ You can use conjoining filler words for more readable language. ``` Advanced Usage -------------- -#####Custom defaults +####Custom defaults You can pass an object to the constructor with your desired default configuration. ```html ``` ->**See it in action:** The [demo page](http://julianlloyd.me/scrollreveal) has been updated with the `reset: true` -

+>**See it in action:** The [demo page](http://julianlloyd.me/scrollreveal) has been updated with the `reset: true` property. #### Easing Control Now you can replace the `move` keyword with easing keywords to control the easing of your reveal animation. From 05e1bc2737c00c2de79c832cc6d2d58e6bebb32a Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 03:11:30 -0800 Subject: [PATCH 33/79] Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e634d58c..a32252d2 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ If set to **1**, the element is considered in the viewport when it is fully visi
Foo
``` -> ***Important Note:** scrollReveal by defaut does not reset reveal animations, and will remove the appended `style` attribute (containing generated CSS) from your elements.

However, to prevent flickering in reveal animations when using the keyword `reset`, scrollReveal does not remove the this appended `style` attribute.

This means using the `reset` keyword may cause the scrollReveal animation CSS properties to override or conflict with any other CSS transform and transition properties on that element. +> **Important Note:** scrollReveal by defaut does not reset reveal animations, and will remove the appended `style` attribute (containing generated CSS) from your elements.

However, to prevent flickering in reveal animations when using the keyword `reset`, scrollReveal does not remove the this appended `style` attribute.

This means using the `reset` keyword may cause the scrollReveal animation CSS properties to override or conflict with any other CSS transform and transition properties on that element. #### Controlling Easing The `move` keyword can be replaced with any one of the following:

From c5f5ae4b173860fe7feee3a252800534d2d03a16 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 04:21:22 -0800 Subject: [PATCH 34/79] Revise README --- README.md | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a32252d2..ab97a839 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Once you have a copy of `scrollReveal.js`, place it in your JavaScript folder, a ```html - + + @@ -155,7 +158,7 @@ You may have dynamically generated HTML in your use case, (AJAX, templates, othe *Example:* ```html - + ``` -#### Reply Your Animations +#### Replay Reveal Animations Due to popular demand, the `reset` keyword was added. Now, you can configure your animations to replay every time they enter the viewport: *example*: diff --git a/README.md b/README.md index ab97a839..a44621aa 100644 --- a/README.md +++ b/README.md @@ -137,10 +137,11 @@ You can pass an object to the constructor with your desired default configuratio // The starting defaults. var config = { + after: '0s', enter: 'bottom', - move: '0', + move: '24px', over: '0.66s', - delay: '0s', + easing: 'ease-in-out', viewportFactor: 0.33, reset: false, init: true diff --git a/scrollReveal.js b/scrollReveal.js index 7d5cf075..c194700b 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -182,10 +182,6 @@ window.scrollReveal = (function (window) { parsed.over = words[i + 1]; return; - case "trigger": - parsed.eventName = words[i + 1]; - return; - default: return; } @@ -198,8 +194,7 @@ window.scrollReveal = (function (window) { /*=============================================================================*/ update: function (el) { - var css = this.genCSS(el), - self = this; + var css = this.genCSS(el); if (!el.getAttribute('data-scrollReveal-initialized')) { el.setAttribute('style', css.initial); @@ -213,19 +208,19 @@ window.scrollReveal = (function (window) { return; } + if (el.getAttribute('data-scrollReveal-complete')) return; + if (this.isElementInViewport(el, this.options.viewportFactor)) { - if (!el.getAttribute('data-scrollReveal-completed')) { - el.setAttribute('style', css.target + css.transition); - } - // Without reset enabled, we can safely remove the style tag - // to prevent CSS specificy wars with authored CSS. - if (!this.options.reset) { - setTimeout(function () { - el.removeAttribute('style'); - el.setAttribute('data-scrollReveal-completed',true); - }, css.totalDuration); - } - return; + el.setAttribute('style', css.target + css.transition); + // Without reset enabled, we can safely remove the style tag + // to prevent CSS specificy wars with authored CSS. + if (!this.options.reset) { + setTimeout(function () { + el.removeAttribute('style'); + el.setAttribute('data-scrollReveal-complete',true); + }, css.totalDuration); + } + return; } }, @@ -284,13 +279,16 @@ window.scrollReveal = (function (window) { "-moz-transition: all " + dur + " " + easing + " " + delay + ";" + "-o-transition: all " + dur + " " + easing + " " + delay + ";" + "transition: all " + dur + " " + easing + " " + delay + ";" + - "-webkit-backface-visibility: hidden"; + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; // The same as transition, but removing the delay for elements fading out. - var reset = "-webkit-transition: all " + dur + " " + easing + ";" + - "-moz-transition: all " + dur + " " + easing + ";" + - "-o-transition: all " + dur + " " + easing + ";" + - "transition: all " + dur + " " + easing + ";"; + var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + + "-moz-transition: all " + dur + " " + easing + " 0s;" + + "-o-transition: all " + dur + " " + easing + " 0s;" + + "transition: all " + dur + " " + easing + " 0s;" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + "-moz-transform: translate" + axis + "(" + dist + ");" + @@ -305,6 +303,7 @@ window.scrollReveal = (function (window) { transition: transition, initial: initial, target: target, + reset: reset, totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) }; }, From b9a8a16b2db0ec6015f4be2892ffe21ad08e5332 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 12:50:01 -0800 Subject: [PATCH 36/79] Update CHANGELOG --- CHANGELOG.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc3b65e..f831610e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,6 @@ -##### Changelog -# v0.0.2 — February 13th, 2014 +###### Changelog (Updated February 13th, 2014) +#### scrollReveal.js v0.0.2 -Breaking Changes ----------------- -#### Renaming Attributes -The `scrollreveal` attribute has changed to `scrollReveal` (updated with camel case) to remain consistent with it’s usage elsewhere. If you’re updating to scrollReveal v0.0.2, make sure your data-attributes are correctly named. -

-*** -

What’s New ---------- #### Manual Instantiation From c0924980679a917adffc62b4b0caa317b7c06c4c Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 13:58:05 -0800 Subject: [PATCH 37/79] Revise README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a44621aa..c5264581 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ You can pass an object to the constructor with your desired default configuratio ``` -By default `init` is set to `true`, meaning `scrollReveal.init()` fires on instantiation. (This registers DOM elements and prepares them to reveal)

You may want to set `init` to `false` if you’re working with templates or other generated content, letting you control when `scrollReveal.init()` is first called.

You can also call this method any time afterwards to re-check all elements in the DOM with `data-scrollReveal` for attributes. +By default `init` is set to `true`, meaning `scrollReveal.init()` fires on instantiation. (This registers DOM elements and prepares them to reveal)

You may want to set `init` to `false` if you’re working with templates or other generated content, letting you control when `scrollReveal.init()` is first called.

You can also call this method any time afterwards to re-check all elements in the DOM for `data-scrollReveal` attributes. #### Generated HTML You may have dynamically generated HTML in your use case, (AJAX, templates, other JavaScript libraries, etc.,) so as mentioned above, the scrollReveal object has the `init()` helper method that checks for new elements in the DOM. @@ -212,6 +212,7 @@ If set to **1**, the element is considered in the viewport when it is fully visi #### Controlling Easing The `move` keyword can be replaced with any one of the following:

+- `ease` - `ease-in` - `ease-out` - `ease-in-out` From 28f5689dc1f5a2b9a9813c9122c1407b0902bd37 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Feb 2014 16:17:56 -0800 Subject: [PATCH 38/79] Prune scrollReveal.js and revise README --- README.md | 9 +++++---- scrollReveal.js | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c5264581..ed140065 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,9 @@ You can easily combine the above pairs to create more dynamic reveal animations. *Example:* ```html
Foo
-
Bar
-
Baz
-
Mel
+
Bar
+
Baz
+
Mel
``` #### Fillers (optional) @@ -211,7 +211,8 @@ If set to **1**, the element is considered in the viewport when it is fully visi > **Important Note:** scrollReveal by defaut does not reset reveal animations, and will remove the appended `style` attribute (containing generated CSS) from your elements once the reveal animation is complete.

However when using `reset` (to prevent flickering in reveal animations), scrollReveal does not remove the appended `style` attribute.

This means using the `reset` keyword may cause the scrollReveal animation CSS properties to override or conflict with any other CSS transform and transition properties on that element. #### Controlling Easing -The `move` keyword can be replaced with any one of the following:

+The `move` keyword can be replaced with any one of the following: + - `ease` - `ease-in` - `ease-out` diff --git a/scrollReveal.js b/scrollReveal.js index c194700b..b3ef4bb1 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -29,7 +29,6 @@ window.scrollReveal = (function (window) { this.docElem = window.document.documentElement; this.options = this.extend(this.defaults, options); - this.self = this; if (this.options.init == true) this.init(); } From 0d942b1a0da5f5cbb34b2535495349a6b11095a8 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Sat, 15 Feb 2014 00:33:34 -0800 Subject: [PATCH 39/79] Update README --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index ed140065..a3fc6d49 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #scrollReveal.js A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment from [@JulianLloyd](https://twitter.com/julianlloyd). -[![scrollReveal version](https://badge.fury.io/gh/julianlloyd%2FscrollReveal.js.png)](http://badge.fury.io/gh/julianlloyd%2FscrollReveal.js) [![Bitdeli Analytics](https://d2weczhvl823v0.cloudfront.net/julianlloyd/scrollreveal.js/trend.png)](https://bitdeli.com/free) +[![scrollReveal version](https://badge.fury.io/gh/julianlloyd%2FscrollReveal.js.png)](http://badge.fury.io/gh/julianlloyd%2FscrollReveal.js) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/julianlloyd/scrollreveal.js/trend.png)](https://bitdeli.com/free "Bitdeli Badge") *** ####**[→ View Demo ←](http://julianlloyd.me/scrollreveal)** *** @@ -23,15 +23,12 @@ Once you have a copy of `scrollReveal.js`, place it in your JavaScript folder, a ```html - - - ``` Basic Usage ----------- From 9f89651b2128d7bc8d29653bdd2238eb5254b15e Mon Sep 17 00:00:00 2001 From: tomByrer Date: Sat, 22 Feb 2014 21:05:52 -0700 Subject: [PATCH 40/79] fewer prefixes -moz- & -o- have been dropped for a while: http://caniuse.com/transforms2d http://caniuse.com/css-transitions --- scrollReveal.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scrollReveal.js b/scrollReveal.js index b3ef4bb1..0e8937b9 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -275,27 +275,21 @@ window.scrollReveal = (function (window) { easing = parsed.easing || this.options.easing; var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + - "-moz-transition: all " + dur + " " + easing + " " + delay + ";" + - "-o-transition: all " + dur + " " + easing + " " + delay + ";" + "transition: all " + dur + " " + easing + " " + delay + ";" + "-webkit-perspective: 1000;" + "-webkit-backface-visibility: hidden;"; // The same as transition, but removing the delay for elements fading out. var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + - "-moz-transition: all " + dur + " " + easing + " 0s;" + - "-o-transition: all " + dur + " " + easing + " 0s;" + "transition: all " + dur + " " + easing + " 0s;" + "-webkit-perspective: 1000;" + "-webkit-backface-visibility: hidden;"; var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + - "-moz-transform: translate" + axis + "(" + dist + ");" + "transform: translate" + axis + "(" + dist + ");" + "opacity: 0;"; var target = "-webkit-transform: translate" + axis + "(0);" + - "-moz-transform: translate" + axis + "(0);" + "transform: translate" + axis + "(0);" + "opacity: 1;"; return { @@ -355,4 +349,4 @@ window.scrollReveal = (function (window) { }; // end scrollReveal.prototype return scrollReveal; -})(window); \ No newline at end of file +})(window); From 8fc593cb94d41da90bdd9e9d06e95d50c96cbf3a Mon Sep 17 00:00:00 2001 From: tomByrer Date: Sat, 22 Feb 2014 21:12:32 -0700 Subject: [PATCH 41/79] + top comment Helpful for many JS minifiers to keep ID, version, author, & copyright/licence --- scrollReveal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scrollReveal.js b/scrollReveal.js index 0e8937b9..d34cf3d8 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -1,3 +1,4 @@ +/*! scrollReveal.js v0.0.3 | (c)2014 Julian Lloyd | MIT license */ /* _ _ _____ _ _ | | | __ \ | | (_) From b0cf725007d662f3d94026b602e9a8cddbf06520 Mon Sep 17 00:00:00 2001 From: tomByrer Date: Sat, 22 Feb 2014 21:13:50 -0700 Subject: [PATCH 42/79] v0.0.3 --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index c641434d..5d8595d6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.0.2", + "version": "0.0.3", "homepage": "https://github.com/julianlloyd/scrollReveal.js", "authors": [ "Julian Lloyd " From 8c32bc58c6230ed949a4b9404f11c647551cd8ef Mon Sep 17 00:00:00 2001 From: tomByrer Date: Sat, 22 Feb 2014 21:20:03 -0700 Subject: [PATCH 43/79] v0.0.3 --- CHANGELOG.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f831610e..896ee03f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ -###### Changelog (Updated February 13th, 2014) -#### scrollReveal.js v0.0.2 +###### scrollReveal.js Changelog + +### v0.0.3 February 22th, 2014 + +* removed `-moz-` & `-o-` from css transitions & transforms +* added top-line comment, intending it to be kept after minification + +### v0.0.2 February 13th, 2014 What’s New ---------- @@ -57,4 +63,4 @@ Now you can replace the `move` keyword with easing keywords to control the easin *example*: ```html
Foo
-``` \ No newline at end of file +``` From 7354d663ca48942d8ffa87b727b8f2f8901b2519 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Fri, 28 Feb 2014 12:11:30 -0800 Subject: [PATCH 44/79] Refactor for non-destructive style attribute logic in Update() method. Fixes #18 --- CHANGELOG.md | 11 ++++++++++- bower.json | 9 ++++++--- scrollReveal.js | 27 ++++++++++++++++++--------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 896ee03f..3cab4613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,21 @@ ###### scrollReveal.js Changelog +### v0.0.4 February 28th, 2014 + +* scrollReveal no longer destroys the existing `style` attribute on revealed elements, but instead, now ammends the necessary reveal animation styles after any existing styles. **(Fixes #18)** + +>**Note:** scrollReveal will still override any existing transition or transform in the `style` attribute. + ### v0.0.3 February 22th, 2014 -* removed `-moz-` & `-o-` from css transitions & transforms +* removed unecessary styles (with `-moz-` & `-o-`) from css transitions & transforms * added top-line comment, intending it to be kept after minification ### v0.0.2 February 13th, 2014 +* Added CHANGELOG +* Improved README + What’s New ---------- #### Manual Instantiation diff --git a/bower.json b/bower.json index 5d8595d6..75a845ca 100644 --- a/bower.json +++ b/bower.json @@ -1,17 +1,20 @@ { "name": "scrollReveal.js", - "version": "0.0.3", + "version": "0.0.4", "homepage": "https://github.com/julianlloyd/scrollReveal.js", "authors": [ - "Julian Lloyd " + "Julian Lloyd " ], "description": "A simple way to create and maintain how elements fade in, triggered when they enter the viewport.", "main": ["scrollReveal.js"], "keywords": [ + "scrollReveal", "animation", "CSS", "transition", - "JavaScript" + "JavaScript", + "scroll", + "reveal" ], "license": "MIT", "ignore": [ diff --git a/scrollReveal.js b/scrollReveal.js index d34cf3d8..1cd002ca 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -1,11 +1,10 @@ -/*! scrollReveal.js v0.0.3 | (c)2014 Julian Lloyd | MIT license */ /* _ _ _____ _ _ | | | __ \ | | (_) ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.0.2 + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.0.4 _/ | |__/ @@ -18,10 +17,13 @@ Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php - scrollReveal.js (c) 2014 Julian Lloyd - =============================================================================*/ +/*! scrollReveal.js v0.0.4 (c) 2014 Julian Lloyd | MIT license */ + +/*===========================================================================*/ + + window.scrollReveal = (function (window) { 'use strict'; @@ -194,16 +196,19 @@ window.scrollReveal = (function (window) { /*=============================================================================*/ update: function (el) { - var css = this.genCSS(el); + var css = this.genCSS(el); + var style = el.getAttribute('style'); + + if (style != null) style += ";"; else style = ""; if (!el.getAttribute('data-scrollReveal-initialized')) { - el.setAttribute('style', css.initial); + el.setAttribute('style', style + css.initial); el.setAttribute('data-scrollReveal-initialized', true); } if (!this.isElementInViewport(el, this.options.viewportFactor)) { if (this.options.reset) { - el.setAttribute('style', css.initial + css.reset); + el.setAttribute('style', style + css.initial + css.reset); } return; } @@ -211,12 +216,16 @@ window.scrollReveal = (function (window) { if (el.getAttribute('data-scrollReveal-complete')) return; if (this.isElementInViewport(el, this.options.viewportFactor)) { - el.setAttribute('style', css.target + css.transition); + el.setAttribute('style', style + css.target + css.transition); // Without reset enabled, we can safely remove the style tag // to prevent CSS specificy wars with authored CSS. if (!this.options.reset) { setTimeout(function () { - el.removeAttribute('style'); + if (style != "") { + el.setAttribute('style', style); + } else { + el.removeAttribute('style'); + } el.setAttribute('data-scrollReveal-complete',true); }, css.totalDuration); } From 579d9f41688368fecf6242c84746659306483079 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Fri, 28 Feb 2014 12:16:49 -0800 Subject: [PATCH 45/79] Update README for v0.0.4 --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index a3fc6d49..a99fbaf5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #scrollReveal.js A simple way to create and maintain how elements fade in, triggered when they enter the viewport. An open-source experiment from [@JulianLloyd](https://twitter.com/julianlloyd). -[![scrollReveal version](https://badge.fury.io/gh/julianlloyd%2FscrollReveal.js.png)](http://badge.fury.io/gh/julianlloyd%2FscrollReveal.js) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/julianlloyd/scrollreveal.js/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +[![scrollReveal version](https://badge.fury.io/gh/julianlloyd%2FscrollReveal.js.png)](http://badge.fury.io/gh/julianlloyd%2FscrollReveal.js) *** ####**[→ View Demo ←](http://julianlloyd.me/scrollreveal)** *** @@ -205,7 +205,6 @@ If set to **1**, the element is considered in the viewport when it is fully visi
Foo
``` -> **Important Note:** scrollReveal by defaut does not reset reveal animations, and will remove the appended `style` attribute (containing generated CSS) from your elements once the reveal animation is complete.

However when using `reset` (to prevent flickering in reveal animations), scrollReveal does not remove the appended `style` attribute.

This means using the `reset` keyword may cause the scrollReveal animation CSS properties to override or conflict with any other CSS transform and transition properties on that element. #### Controlling Easing The `move` keyword can be replaced with any one of the following: From 8c01bcc133a9ab6c95132a828883aa8e3691d18a Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Fri, 28 Feb 2014 12:18:57 -0800 Subject: [PATCH 46/79] Update CHANGELOG for v0.0.4 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cab4613..695c4d7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### v0.0.4 February 28th, 2014 -* scrollReveal no longer destroys the existing `style` attribute on revealed elements, but instead, now ammends the necessary reveal animation styles after any existing styles. **(Fixes #18)** +* scrollReveal no longer destroys the existing `style` attribute on revealed elements, but instead, now appends the necessary reveal animation styles after any existing styles. **(Fixes #18)** >**Note:** scrollReveal will still override any existing transition or transform in the `style` attribute. From 5ce0e23fa98c6a511eef6180c5ce5c506ba393f8 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Mon, 3 Mar 2014 11:59:53 -0500 Subject: [PATCH 47/79] change data-scrollReveal to data-scroll-reveal --- README.md | 48 ++++++++++++++++++++++++------------------------ scrollReveal.js | 4 ++-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a99fbaf5..d6e43a6c 100644 --- a/README.md +++ b/README.md @@ -32,22 +32,22 @@ Once you have a copy of `scrollReveal.js`, place it in your JavaScript folder, a ``` Basic Usage ----------- -By adding a `data-scrollReveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport: +By adding a `data-scroll-reveal` attribute to an element, it will automatically be revealed (using default values) as soon as the element is within the viewport: ```html -
Hello world!
+
Hello world!
``` **But wait!** It’s more fun if you define your own reveal animation parameters, which you can do using using natural, declarative language: ```html -
Foo
-
Bar
-
Baz
+
Foo
+
Bar
+
Baz
``` Getting Started --------------- -What you enter into the `data-scrollReveal` attribute is parsed for specific words: +What you enter into the `data-scroll-reveal` attribute is parsed for specific words: - **keywords** that expect to be followed by a **value**.

- **fillers** as natural language sugar. (optional) @@ -60,7 +60,7 @@ These specific **keyword** / **value** pairs allow you to describe basic reveal *Example:* ```html -
Foo
+
Foo
``` *** **keyword:** `move` — The distance your revealing element travels.
@@ -68,7 +68,7 @@ These specific **keyword** / **value** pairs allow you to describe basic reveal *Example:* ```html -
Bar
+
Bar
``` *** **keyword:** `over` — The duration of your reveal animation.
@@ -77,7 +77,7 @@ These specific **keyword** / **value** pairs allow you to describe basic reveal *Example:* ```html -
Baz
+
Baz
``` *** **keyword:** `after/wait` — The duration before your reveal begins.
@@ -87,8 +87,8 @@ These specific **keyword** / **value** pairs allow you to describe basic reveal *Example:* ```html -
Mel
-
Mel
+
Mel
+
Mel
``` ####Combining Keyword/Value Pairs @@ -96,10 +96,10 @@ You can easily combine the above pairs to create more dynamic reveal animations. *Example:* ```html -
Foo
-
Bar
-
Baz
-
Mel
+
Foo
+
Bar
+
Baz
+
Mel
``` #### Fillers (optional) @@ -116,10 +116,10 @@ You can use conjoining filler words for more readable language. *Example*: ```html -
Foo
-
Bar
-
Baz
-
Mel
+
Foo
+
Bar
+
Baz
+
Mel
``` Advanced Usage @@ -149,7 +149,7 @@ You can pass an object to the constructor with your desired default configuratio ``` -By default `init` is set to `true`, meaning `scrollReveal.init()` fires on instantiation. (This registers DOM elements and prepares them to reveal)

You may want to set `init` to `false` if you’re working with templates or other generated content, letting you control when `scrollReveal.init()` is first called.

You can also call this method any time afterwards to re-check all elements in the DOM for `data-scrollReveal` attributes. +By default `init` is set to `true`, meaning `scrollReveal.init()` fires on instantiation. (This registers DOM elements and prepares them to reveal)

You may want to set `init` to `false` if you’re working with templates or other generated content, letting you control when `scrollReveal.init()` is first called.

You can also call this method any time afterwards to re-check all elements in the DOM for `data-scroll-reveal` attributes. #### Generated HTML You may have dynamically generated HTML in your use case, (AJAX, templates, other JavaScript libraries, etc.,) so as mentioned above, the scrollReveal object has the `init()` helper method that checks for new elements in the DOM. @@ -172,7 +172,7 @@ You may have dynamically generated HTML in your use case, (AJAX, templates, othe window.scrollReveal = new scrollReveal( config ); // Dummy AJAX return object: - var data = { newElementHtml: '
Foo
' } + var data = { newElementHtml: '
Foo
' } var container = document.getElementById('#container'); container.innerHTML( data.newElementHTML ); @@ -203,7 +203,7 @@ If set to **1**, the element is considered in the viewport when it is fully visi **Keyword:** `reset` — replay reveal animations every time elements enter the viewport. ```html -
Foo
+
Foo
``` #### Controlling Easing @@ -216,7 +216,7 @@ The `move` keyword can be replaced with any one of the following: *Example:* ```html -
Foo
+
Foo
``` Browser Support @@ -243,4 +243,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/scrollReveal.js b/scrollReveal.js index 1cd002ca..f54a6dd8 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -67,7 +67,7 @@ window.scrollReveal = (function (window) { // Check DOM for the data-scrollReveal attribute // and initialize all found elements. - this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scrollReveal]')); + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); this.elems.forEach(function (el, i) { self.update(el); }); @@ -114,7 +114,7 @@ window.scrollReveal = (function (window) { parseLanguage: function (el) { // Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), parsed = {}; function filter (words) { From 3bf1f1fd6fe76c7bb613237cd1b0fcb6f1590c1a Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Mon, 3 Mar 2014 14:14:02 -0500 Subject: [PATCH 48/79] add build process, umd wrapper and minified version --- .gitignore | 1 + Gulpfile.js | 20 ++ dist/scrollReveal.js | 369 ++++++++++++++++++++++++++ dist/scrollReveal.min.js | 1 + package.json | 39 +++ scrollReveal.js | 542 +++++++++++++++++++-------------------- 6 files changed, 697 insertions(+), 275 deletions(-) create mode 100644 Gulpfile.js create mode 100644 dist/scrollReveal.js create mode 100644 dist/scrollReveal.min.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index ac39bdd5..5ab90ec5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *~ *.lock *.DS_Store +node_modules diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 00000000..08c2a231 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,20 @@ +var gulp = require('gulp'), + uglify = require('gulp-uglify'), + umd = require('gulp-wrap-umd'), + rename = require('gulp-rename'); + +gulp.task('wrap', function(){ + gulp.src('scrollReveal.js') + .pipe(umd({ namespace: 'scrollReveal', exports: 'scrollReveal' })) + .pipe(gulp.dest('dist')) +}); + +gulp.task('minify', function(){ + gulp.src('scrollReveal.js') + .pipe(umd({ namespace: 'scrollReveal', exports: 'scrollReveal' })) + .pipe(uglify()) + .pipe(rename('scrollReveal.min.js')) + .pipe(gulp.dest('dist')) +}); + +gulp.task('default', ['wrap', 'minify']); diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js new file mode 100644 index 00000000..8f4daf01 --- /dev/null +++ b/dist/scrollReveal.js @@ -0,0 +1,369 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + define(factory); + } else if (typeof exports === 'object') { + module.exports = factory(require, exports, module); + } else { + root.scrollReveal = factory(); + } +}(this, function(require, exports, module) { + +/* + _ _ _____ _ _ + | | | __ \ | | (_) + ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ + / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| + \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.0.4 + _/ | + |__/ + + "Declarative on-scroll reveal animations." + +/*============================================================================= + + scrollReveal.js was inspired by cbpScroller.js (c) 2014 Codrops. + + Licensed under the MIT license. + http://www.opensource.org/licenses/mit-license.php + +=============================================================================*/ + +/*! scrollReveal.js v0.0.4 (c) 2014 Julian Lloyd | MIT license */ + +/*===========================================================================*/ + +function scrollReveal(options) { + + this.docElem = window.document.documentElement; + this.options = this.extend(this.defaults, options); + + if (this.options.init == true) this.init(); +} + +scrollReveal.prototype = { + + defaults: { + after: '0s', + enter: 'bottom', + move: '24px', + over: '0.66s', + easing: 'ease-in-out', + +// if 0, the element is considered in the viewport as soon as it enters +// if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33, + +// if false, animations occur only once +// if true, animations occur each time an element enters the viewport + reset: false, + +// if true, scrollReveal.init() is automaticaly called upon instantiation + init: true + }, + + /*=============================================================================*/ + + init: function () { + + this.scrolled = false; + + var self = this; + +// Check DOM for the data-scrollReveal attribute +// and initialize all found elements. + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); + this.elems.forEach(function (el, i) { + self.update(el); + }); + + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; + + var resizeHandler = function () { + + // If we’re still waiting for settimeout, reset the timer. + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + self.resizeTimeout = setTimeout(delayed, 200); + }; + + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, + + /*=============================================================================*/ + + _scrollPage: function () { + var self = this; + + this.elems.forEach(function (el, i) { + self.update(el); + }); + this.scrolled = false; + }, + + /*=============================================================================*/ + + parseLanguage: function (el) { + +// Splits on a sequence of one or more commas or spaces. + var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), + parsed = {}; + + function filter (words) { + var ret = [], + + blacklist = [ + "from", + "the", + "and", + "then", + "but", + "with" + ]; + + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); + + return ret; + } + + words = filter(words); + + words.forEach(function (word, i) { + + switch (word) { + case "enter": + parsed.enter = words[i + 1]; + return; + + case "after": + parsed.after = words[i + 1]; + return; + + case "wait": + parsed.after = words[i + 1]; + return; + + case "move": + parsed.move = words[i + 1]; + return; + + case "ease": + parsed.move = words[i + 1]; + parsed.ease = "ease"; + return; + + case "ease-in": + parsed.move = words[i + 1]; + parsed.easing = "ease-in"; + return; + + case "ease-in-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-in-out"; + return; + + case "ease-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-out"; + return; + + case "over": + parsed.over = words[i + 1]; + return; + + default: + return; + } + }); + + return parsed; + }, + + + /*=============================================================================*/ + + update: function (el) { + var css = this.genCSS(el); + var style = el.getAttribute('style'); + + if (style != null) style += ";"; else style = ""; + + if (!el.getAttribute('data-scrollReveal-initialized')) { + el.setAttribute('style', style + css.initial); + el.setAttribute('data-scrollReveal-initialized', true); + } + + if (!this.isElementInViewport(el, this.options.viewportFactor)) { + if (this.options.reset) { + el.setAttribute('style', style + css.initial + css.reset); + } + return; + } + + if (el.getAttribute('data-scrollReveal-complete')) return; + + if (this.isElementInViewport(el, this.options.viewportFactor)) { + el.setAttribute('style', style + css.target + css.transition); + // Without reset enabled, we can safely remove the style tag + // to prevent CSS specificy wars with authored CSS. + if (!this.options.reset) { + setTimeout(function () { + if (style != "") { + el.setAttribute('style', style); + } else { + el.removeAttribute('style'); + } + el.setAttribute('data-scrollReveal-complete',true); + }, css.totalDuration); + } + return; + } + }, + + /*=============================================================================*/ + + genCSS: function (el) { + var parsed = this.parseLanguage(el), + enter, + axis; + + if (parsed.enter) { + + if (parsed.enter == "top" || parsed.enter == "bottom") { + enter = parsed.enter; + axis = "y"; + } + + if (parsed.enter == "left" || parsed.enter == "right") { + enter = parsed.enter; + axis = "x"; + } + + } else { + + if (this.options.enter == "top" || this.options.enter == "bottom") { + enter = this.options.enter + axis = "y"; + } + + if (this.options.enter == "left" || this.options.enter == "right") { + enter = this.options.enter + axis = "x"; + } + } + +// After all values are parsed, let’s make sure our our +// pixel distance is negative for top and left entrances. +// +// ie. "move 25px from top" starts at 'top: -25px' in CSS. + + if (enter == "top" || enter == "left") { + if (!typeof parsed.move == "undefined") { + parsed.move = "-" + parsed.move; + } + else { + parsed.move = "-" + this.options.move; + } + } + + var dist = parsed.move || this.options.move, + dur = parsed.over || this.options.over, + delay = parsed.after || this.options.after, + easing = parsed.easing || this.options.easing; + + var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + + "transition: all " + dur + " " + easing + " " + delay + ";" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + +// The same as transition, but removing the delay for elements fading out. + var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + + "transition: all " + dur + " " + easing + " 0s;" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + reset: reset, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + getViewportH : function () { + var client = this.docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + }, + + getOffset : function(el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) + + return { + top: offsetTop, + left: offsetLeft + } + }, + + isElementInViewport : function(el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + this.getViewportH(), + elH = el.offsetHeight, + elTop = this.getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + }, + + extend: function (a, b){ + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; + } +}; // end scrollReveal.prototype + +return scrollReveal; + +})); diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js new file mode 100644 index 00000000..857cb3fc --- /dev/null +++ b/dist/scrollReveal.min.js @@ -0,0 +1 @@ +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){function t(t){this.docElem=window.document.documentElement,this.options=this.extend(this.defaults,t),1==this.options.init&&this.init()}return t.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var t=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(e){t.update(e)});var e=function(){t.scrolled||(t.scrolled=!0,setTimeout(function(){t._scrollPage()},60))},i=function(){function e(){t._scrollPage(),t.resizeTimeout=null}t.resizeTimeout&&clearTimeout(t.resizeTimeout),t.resizeTimeout=setTimeout(e,200)};window.addEventListener("scroll",e,!1),window.addEventListener("resize",i,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=t.getAttribute("style");return null!=i?i+=";":i="",t.getAttribute("data-scrollReveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scrollReveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scrollReveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scrollReveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+n+" "+a+" "+s+";transition: all "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+n+" "+a+" 0s;transition: all "+n+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var t=this.docElem.clientHeight,e=window.innerHeight;return e>t?e:t},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(t,e){var i=window.pageYOffset,o=i+this.getViewportH(),r=t.offsetHeight,n=this.getOffset(t).top,s=n+r,e=e||0;return o>=n+r*e&&s>=i},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},t}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 00000000..61f65849 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "scrollReveal.js", + "version": "0.0.0", + "description": "Declarative on-scroll reveal animations", + "main": "scrollReveal.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "browserify test/test.js > test/bundle.js; open test/test.html" + }, + "repository": { + "type": "git", + "url": "https://github.com/julianlloyd/scrollReveal.js.git" + }, + "author": "Julian Lloyd", + "license": "MIT", + "bugs": { + "url": "https://github.com/julianlloyd/scrollReveal.js/issues" + }, + "testling": { + "files": "test/*.js", + "browsers": [ + "ie/8..latest", + "chrome/latest", + "firefox/latest" + ] + }, + "homepage": "https://github.com/julianlloyd/scrollReveal.js", + "devDependencies": { + "tape": "*", + "testling": "*", + "browserify": "*", + "gulp": "*", + "gulp-uglify": "*", + "gulp-wrap-umd": "*", + "gulp-rename": "~1.1.0" + } +} diff --git a/scrollReveal.js b/scrollReveal.js index f54a6dd8..b39ebee7 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -23,340 +23,332 @@ /*===========================================================================*/ +function scrollReveal(options) { -window.scrollReveal = (function (window) { + this.docElem = window.document.documentElement; + this.options = this.extend(this.defaults, options); - 'use strict'; + if (this.options.init == true) this.init(); +} - function scrollReveal(options) { +scrollReveal.prototype = { - this.docElem = window.document.documentElement; - this.options = this.extend(this.defaults, options); + defaults: { + after: '0s', + enter: 'bottom', + move: '24px', + over: '0.66s', + easing: 'ease-in-out', - if (this.options.init == true) this.init(); - } +// if 0, the element is considered in the viewport as soon as it enters +// if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33, - scrollReveal.prototype = { +// if false, animations occur only once +// if true, animations occur each time an element enters the viewport + reset: false, - defaults: { - after: '0s', - enter: 'bottom', - move: '24px', - over: '0.66s', - easing: 'ease-in-out', +// if true, scrollReveal.init() is automaticaly called upon instantiation + init: true + }, - // if 0, the element is considered in the viewport as soon as it enters - // if 1, the element is considered in the viewport when it's fully visible - viewportFactor: 0.33, + /*=============================================================================*/ - // if false, animations occur only once - // if true, animations occur each time an element enters the viewport - reset: false, + init: function () { - // if true, scrollReveal.init() is automaticaly called upon instantiation - init: true - }, + this.scrolled = false; - /*=============================================================================*/ + var self = this; - init: function () { +// Check DOM for the data-scrollReveal attribute +// and initialize all found elements. + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); + this.elems.forEach(function (el, i) { + self.update(el); + }); - this.scrolled = false; + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; + + var resizeHandler = function () { + + // If we’re still waiting for settimeout, reset the timer. + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + self.resizeTimeout = setTimeout(delayed, 200); + }; + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, + + /*=============================================================================*/ + + _scrollPage: function () { var self = this; - // Check DOM for the data-scrollReveal attribute - // and initialize all found elements. - this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); this.elems.forEach(function (el, i) { self.update(el); }); + this.scrolled = false; + }, - var scrollHandler = function () { - if (!self.scrolled) { - self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); - } - }; + /*=============================================================================*/ - var resizeHandler = function () { + parseLanguage: function (el) { - // If we’re still waiting for settimeout, reset the timer. - if (self.resizeTimeout) { - clearTimeout(self.resizeTimeout); - } - function delayed() { - self._scrollPage(); - self.resizeTimeout = null; - } - self.resizeTimeout = setTimeout(delayed, 200); - }; +// Splits on a sequence of one or more commas or spaces. + var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), + parsed = {}; - window.addEventListener('scroll', scrollHandler, false); - window.addEventListener('resize', resizeHandler, false); - }, + function filter (words) { + var ret = [], - /*=============================================================================*/ + blacklist = [ + "from", + "the", + "and", + "then", + "but", + "with" + ]; - _scrollPage: function () { - var self = this; + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); - this.elems.forEach(function (el, i) { - self.update(el); - }); - this.scrolled = false; - }, + return ret; + } - /*=============================================================================*/ + words = filter(words); - parseLanguage: function (el) { + words.forEach(function (word, i) { - // Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), - parsed = {}; + switch (word) { + case "enter": + parsed.enter = words[i + 1]; + return; - function filter (words) { - var ret = [], + case "after": + parsed.after = words[i + 1]; + return; - blacklist = [ - "from", - "the", - "and", - "then", - "but", - "with" - ]; + case "wait": + parsed.after = words[i + 1]; + return; - words.forEach(function (word, i) { - if (blacklist.indexOf(word) > -1) { - return; - } - ret.push(word); - }); + case "move": + parsed.move = words[i + 1]; + return; - return ret; - } + case "ease": + parsed.move = words[i + 1]; + parsed.ease = "ease"; + return; - words = filter(words); + case "ease-in": + parsed.move = words[i + 1]; + parsed.easing = "ease-in"; + return; - words.forEach(function (word, i) { + case "ease-in-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-in-out"; + return; - switch (word) { - case "enter": - parsed.enter = words[i + 1]; - return; - - case "after": - parsed.after = words[i + 1]; - return; - - case "wait": - parsed.after = words[i + 1]; - return; - - case "move": - parsed.move = words[i + 1]; - return; - - case "ease": - parsed.move = words[i + 1]; - parsed.ease = "ease"; - return; - - case "ease-in": - parsed.move = words[i + 1]; - parsed.easing = "ease-in"; - return; - - case "ease-in-out": - parsed.move = words[i + 1]; - parsed.easing = "ease-in-out"; - return; - - case "ease-out": - parsed.move = words[i + 1]; - parsed.easing = "ease-out"; - return; - - case "over": - parsed.over = words[i + 1]; - return; - - default: - return; - } - }); + case "ease-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-out"; + return; - return parsed; - }, + case "over": + parsed.over = words[i + 1]; + return; + default: + return; + } + }); - /*=============================================================================*/ + return parsed; + }, - update: function (el) { - var css = this.genCSS(el); - var style = el.getAttribute('style'); - if (style != null) style += ";"; else style = ""; + /*=============================================================================*/ - if (!el.getAttribute('data-scrollReveal-initialized')) { - el.setAttribute('style', style + css.initial); - el.setAttribute('data-scrollReveal-initialized', true); - } + update: function (el) { + var css = this.genCSS(el); + var style = el.getAttribute('style'); - if (!this.isElementInViewport(el, this.options.viewportFactor)) { - if (this.options.reset) { - el.setAttribute('style', style + css.initial + css.reset); - } - return; - } + if (style != null) style += ";"; else style = ""; - if (el.getAttribute('data-scrollReveal-complete')) return; - - if (this.isElementInViewport(el, this.options.viewportFactor)) { - el.setAttribute('style', style + css.target + css.transition); - // Without reset enabled, we can safely remove the style tag - // to prevent CSS specificy wars with authored CSS. - if (!this.options.reset) { - setTimeout(function () { - if (style != "") { - el.setAttribute('style', style); - } else { - el.removeAttribute('style'); - } - el.setAttribute('data-scrollReveal-complete',true); - }, css.totalDuration); - } - return; + if (!el.getAttribute('data-scrollReveal-initialized')) { + el.setAttribute('style', style + css.initial); + el.setAttribute('data-scrollReveal-initialized', true); + } + + if (!this.isElementInViewport(el, this.options.viewportFactor)) { + if (this.options.reset) { + el.setAttribute('style', style + css.initial + css.reset); } - }, + return; + } - /*=============================================================================*/ + if (el.getAttribute('data-scrollReveal-complete')) return; + + if (this.isElementInViewport(el, this.options.viewportFactor)) { + el.setAttribute('style', style + css.target + css.transition); + // Without reset enabled, we can safely remove the style tag + // to prevent CSS specificy wars with authored CSS. + if (!this.options.reset) { + setTimeout(function () { + if (style != "") { + el.setAttribute('style', style); + } else { + el.removeAttribute('style'); + } + el.setAttribute('data-scrollReveal-complete',true); + }, css.totalDuration); + } + return; + } + }, - genCSS: function (el) { - var parsed = this.parseLanguage(el), - enter, - axis; + /*=============================================================================*/ - if (parsed.enter) { + genCSS: function (el) { + var parsed = this.parseLanguage(el), + enter, + axis; - if (parsed.enter == "top" || parsed.enter == "bottom") { - enter = parsed.enter; - axis = "y"; - } + if (parsed.enter) { - if (parsed.enter == "left" || parsed.enter == "right") { - enter = parsed.enter; - axis = "x"; - } + if (parsed.enter == "top" || parsed.enter == "bottom") { + enter = parsed.enter; + axis = "y"; + } - } else { + if (parsed.enter == "left" || parsed.enter == "right") { + enter = parsed.enter; + axis = "x"; + } - if (this.options.enter == "top" || this.options.enter == "bottom") { - enter = this.options.enter - axis = "y"; - } + } else { - if (this.options.enter == "left" || this.options.enter == "right") { - enter = this.options.enter - axis = "x"; - } + if (this.options.enter == "top" || this.options.enter == "bottom") { + enter = this.options.enter + axis = "y"; } - // After all values are parsed, let’s make sure our our - // pixel distance is negative for top and left entrances. - // - // ie. "move 25px from top" starts at 'top: -25px' in CSS. - - if (enter == "top" || enter == "left") { - if (!typeof parsed.move == "undefined") { - parsed.move = "-" + parsed.move; - } - else { - parsed.move = "-" + this.options.move; - } + if (this.options.enter == "left" || this.options.enter == "right") { + enter = this.options.enter + axis = "x"; } + } - var dist = parsed.move || this.options.move, - dur = parsed.over || this.options.over, - delay = parsed.after || this.options.after, - easing = parsed.easing || this.options.easing; - - var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + - "transition: all " + dur + " " + easing + " " + delay + ";" + - "-webkit-perspective: 1000;" + - "-webkit-backface-visibility: hidden;"; - - // The same as transition, but removing the delay for elements fading out. - var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + - "transition: all " + dur + " " + easing + " 0s;" + - "-webkit-perspective: 1000;" + - "-webkit-backface-visibility: hidden;"; - - var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + - "transform: translate" + axis + "(" + dist + ");" + - "opacity: 0;"; - - var target = "-webkit-transform: translate" + axis + "(0);" + - "transform: translate" + axis + "(0);" + - "opacity: 1;"; - return { - transition: transition, - initial: initial, - target: target, - reset: reset, - totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) - }; - }, - - getViewportH : function () { - var client = this.docElem['clientHeight'], - inner = window['innerHeight']; - - return (client < inner) ? inner : client; - }, - - getOffset : function(el) { - var offsetTop = 0, - offsetLeft = 0; - - do { - if (!isNaN(el.offsetTop)) { - offsetTop += el.offsetTop; - } - if (!isNaN(el.offsetLeft)) { - offsetLeft += el.offsetLeft; - } - } while (el = el.offsetParent) +// After all values are parsed, let’s make sure our our +// pixel distance is negative for top and left entrances. +// +// ie. "move 25px from top" starts at 'top: -25px' in CSS. - return { - top: offsetTop, - left: offsetLeft + if (enter == "top" || enter == "left") { + if (!typeof parsed.move == "undefined") { + parsed.move = "-" + parsed.move; } - }, - - isElementInViewport : function(el, h) { - var scrolled = window.pageYOffset, - viewed = scrolled + this.getViewportH(), - elH = el.offsetHeight, - elTop = this.getOffset(el).top, - elBottom = elTop + elH, - h = h || 0; - - return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - }, - - extend: function (a, b){ - for (var key in b) { - if (b.hasOwnProperty(key)) { - a[key] = b[key]; - } + else { + parsed.move = "-" + this.options.move; } - return a; } - }; // end scrollReveal.prototype - return scrollReveal; -})(window); + var dist = parsed.move || this.options.move, + dur = parsed.over || this.options.over, + delay = parsed.after || this.options.after, + easing = parsed.easing || this.options.easing; + + var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + + "transition: all " + dur + " " + easing + " " + delay + ";" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + +// The same as transition, but removing the delay for elements fading out. + var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + + "transition: all " + dur + " " + easing + " 0s;" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + reset: reset, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + getViewportH : function () { + var client = this.docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + }, + + getOffset : function(el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) + + return { + top: offsetTop, + left: offsetLeft + } + }, + + isElementInViewport : function(el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + this.getViewportH(), + elH = el.offsetHeight, + elTop = this.getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + }, + + extend: function (a, b){ + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; + } +}; // end scrollReveal.prototype From cc84a4a9e98ef4ce06b4189a5f4927d17211c0ed Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Fri, 28 Feb 2014 19:08:33 -0500 Subject: [PATCH 49/79] implement basic test suite - based on tape and testling - does not currently work on testling-ci - this is probably testling-ci's fault - does work quite nicely locally - https://github.com/substack/testling/issues/68 --- .gitignore | 1 + CONTRIBUTING.md | 8 ++++++++ package.json | 13 +++++++++---- test/test.html | 5 +++++ test/test.js | 7 +++++++ 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 test/test.html create mode 100644 test/test.js diff --git a/.gitignore b/.gitignore index 5ab90ec5..934c601a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.lock *.DS_Store node_modules +test/bundle.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..3e2e8ff3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,8 @@ +Contributing +------------ + +### Running the Tests + +1. Make sure [nodejs](http://nodejs.org) is installed +2. Run `npm install -g browserify testling; npm i` from your command line +3. Run `npm test` from your command line and check the console diff --git a/package.json b/package.json index 61f65849..5815f80c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "scrollReveal.js", - "version": "0.0.0", + "version": "0.0.4", "description": "Declarative on-scroll reveal animations", "main": "scrollReveal.js", "directories": { "test": "test" }, "scripts": { - "test": "browserify test/test.js > test/bundle.js; open test/test.html" + "test": "browserify test/test.js > test/bundle.js; testling", + "browser": "browserify test/test.js > test/bundle.js; open test/test.html" }, "repository": { "type": "git", @@ -19,11 +20,15 @@ "url": "https://github.com/julianlloyd/scrollReveal.js/issues" }, "testling": { - "files": "test/*.js", + "html": "test/test.html", "browsers": [ "ie/8..latest", "chrome/latest", - "firefox/latest" + "firefox/latest", + "safari/latest", + "iphone/6", + "ipad/6", + "android-browser/latest" ] }, "homepage": "https://github.com/julianlloyd/scrollReveal.js", diff --git a/test/test.html b/test/test.html new file mode 100644 index 00000000..eb2e4779 --- /dev/null +++ b/test/test.html @@ -0,0 +1,5 @@ +
test 1
+ + + + diff --git a/test/test.js b/test/test.js new file mode 100644 index 00000000..4317ec3b --- /dev/null +++ b/test/test.js @@ -0,0 +1,7 @@ +var test = require('tape'); + +test('basic', function(t){ + var test_styles = document.querySelector('div').style; + t.equal(test_styles.cssText, '-webkit-transform: translateX(0px); opacity: 1; -webkit-transition-property: all; -webkit-transition-duration: 1.33s; -webkit-transition-timing-function: ease-in-out; -webkit-transition-delay: 0s; -webkit-perspective: 1000; -webkit-backface-visibility: hidden; '); + t.end(); +}); From 3e59de9a69b469dd5df6368c80c933b94b44ef85 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 5 Mar 2014 14:54:19 -0800 Subject: [PATCH 50/79] Integrate testing and build process. Also fixes #23 --- CHANGELOG.md | 10 + README.md | 2 + dist/scrollReveal.js | 549 ++++++++++++++++++++------------------- dist/scrollReveal.min.js | 2 +- package.json | 2 +- scrollReveal.js | 549 ++++++++++++++++++++------------------- 6 files changed, 578 insertions(+), 536 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 695c4d7b..e085dbbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ ###### scrollReveal.js Changelog +### v0.1.0 march 5th, 2014 + +* scrollReveal.js now has a `dist` folder containing the AMD/CommonJS compatibile library. +* [Gulp](http://gulpjs.com/) has been integrated, facilitating the build process. +* Basic testing using [Testling](https://ci.testling.com/) has been put in place. + +Breaking Changes +---------------- +scrollReveal is now implemented using the `data-scroll-reveal` attribute, **NOT** `data-scrollReveal`. + ### v0.0.4 February 28th, 2014 * scrollReveal no longer destroys the existing `style` attribute on revealed elements, but instead, now appends the necessary reveal animation styles after any existing styles. **(Fixes #18)** diff --git a/README.md b/README.md index d6e43a6c..2c52f915 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,8 @@ Community feedback and involvement is highly encouraged. #### Special Thanks scrollReveal.js was inspired by the awesome [cbpScroller.js](http://tympanus.net/codrops/2013/07/18/on-scroll-effect-layout/) by [Mary Lou](https://twitter.com/crnacura). Copyright © 2014 [Codrops](http://tympanus.net/codrops/). +Also, a special thanks to Jeff Escalante ([Jenius](https://github.com/jenius)) for setting up the build process, and his ongoing help with testing and the JavaScript API. + License ------- diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index 8f4daf01..0758f306 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -15,7 +15,7 @@ ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.0.4 + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.0 _/ | |__/ @@ -30,339 +30,354 @@ =============================================================================*/ -/*! scrollReveal.js v0.0.4 (c) 2014 Julian Lloyd | MIT license */ +/*! scrollReveal.js v0.1.0 (c) 2014 Julian Lloyd | MIT license */ /*===========================================================================*/ -function scrollReveal(options) { - this.docElem = window.document.documentElement; - this.options = this.extend(this.defaults, options); +window.scrollReveal = (function (window) { - if (this.options.init == true) this.init(); -} + 'use strict'; -scrollReveal.prototype = { + function scrollReveal(options) { - defaults: { - after: '0s', - enter: 'bottom', - move: '24px', - over: '0.66s', - easing: 'ease-in-out', + this.docElem = window.document.documentElement; + this.options = this.extend(this.defaults, options); + this.styleBank = []; -// if 0, the element is considered in the viewport as soon as it enters -// if 1, the element is considered in the viewport when it's fully visible - viewportFactor: 0.33, - -// if false, animations occur only once -// if true, animations occur each time an element enters the viewport - reset: false, - -// if true, scrollReveal.init() is automaticaly called upon instantiation - init: true - }, - - /*=============================================================================*/ - - init: function () { + if (this.options.init == true) this.init(); + } - this.scrolled = false; + scrollReveal.prototype = { - var self = this; + defaults: { + after: '0s', + enter: 'bottom', + move: '24px', + over: '0.66s', + easing: 'ease-in-out', -// Check DOM for the data-scrollReveal attribute -// and initialize all found elements. - this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); - this.elems.forEach(function (el, i) { - self.update(el); - }); + // if 0, the element is considered in the viewport as soon as it enters + // if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33, - var scrollHandler = function () { - if (!self.scrolled) { - self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); - } - }; + // if false, animations occur only once + // if true, animations occur each time an element enters the viewport + reset: false, - var resizeHandler = function () { + // if true, scrollReveal.init() is automaticaly called upon instantiation + init: true + }, - // If we’re still waiting for settimeout, reset the timer. - if (self.resizeTimeout) { - clearTimeout(self.resizeTimeout); - } - function delayed() { - self._scrollPage(); - self.resizeTimeout = null; - } - self.resizeTimeout = setTimeout(delayed, 200); - }; + /*=============================================================================*/ - window.addEventListener('scroll', scrollHandler, false); - window.addEventListener('resize', resizeHandler, false); - }, + init: function () { - /*=============================================================================*/ + this.scrolled = false; - _scrollPage: function () { var self = this; + // Check DOM for the data-scrollReveal attribute + // and initialize all found elements. + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scrollReveal]')); this.elems.forEach(function (el, i) { self.update(el); }); - this.scrolled = false; - }, - /*=============================================================================*/ + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; - parseLanguage: function (el) { + var resizeHandler = function () { -// Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), - parsed = {}; + // If we’re still waiting for settimeout, reset the timer. + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + self.resizeTimeout = setTimeout(delayed, 200); + }; - function filter (words) { - var ret = [], + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, - blacklist = [ - "from", - "the", - "and", - "then", - "but", - "with" - ]; + /*=============================================================================*/ - words.forEach(function (word, i) { - if (blacklist.indexOf(word) > -1) { - return; - } - ret.push(word); - }); + _scrollPage: function () { + var self = this; - return ret; - } + this.elems.forEach(function (el, i) { + self.update(el); + }); + this.scrolled = false; + }, - words = filter(words); + /*=============================================================================*/ - words.forEach(function (word, i) { + parseLanguage: function (el) { - switch (word) { - case "enter": - parsed.enter = words[i + 1]; - return; + // Splits on a sequence of one or more commas or spaces. + var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + parsed = {}; - case "after": - parsed.after = words[i + 1]; - return; + function filter (words) { + var ret = [], - case "wait": - parsed.after = words[i + 1]; - return; + blacklist = [ + "from", + "the", + "and", + "then", + "but", + "with" + ]; - case "move": - parsed.move = words[i + 1]; - return; + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); - case "ease": - parsed.move = words[i + 1]; - parsed.ease = "ease"; - return; + return ret; + } - case "ease-in": - parsed.move = words[i + 1]; - parsed.easing = "ease-in"; - return; + words = filter(words); - case "ease-in-out": - parsed.move = words[i + 1]; - parsed.easing = "ease-in-out"; - return; + words.forEach(function (word, i) { - case "ease-out": - parsed.move = words[i + 1]; - parsed.easing = "ease-out"; - return; + switch (word) { + case "enter": + parsed.enter = words[i + 1]; + return; + + case "after": + parsed.after = words[i + 1]; + return; + + case "wait": + parsed.after = words[i + 1]; + return; + + case "move": + parsed.move = words[i + 1]; + return; + + case "ease": + parsed.move = words[i + 1]; + parsed.ease = "ease"; + return; + + case "ease-in": + parsed.move = words[i + 1]; + parsed.easing = "ease-in"; + return; + + case "ease-in-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-in-out"; + return; + + case "ease-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-out"; + return; + + case "over": + parsed.over = words[i + 1]; + return; + + default: + return; + } + }); - case "over": - parsed.over = words[i + 1]; - return; + return parsed; + }, - default: - return; - } - }); - return parsed; - }, + /*=============================================================================*/ + update: function (el) { - /*=============================================================================*/ + // Capture original style attribute + if (!this.styleBank[el]) { + this.styleBank[el] = el.getAttribute('style'); + } - update: function (el) { - var css = this.genCSS(el); - var style = el.getAttribute('style'); + var css = this.genCSS(el); + var style = this.styleBank[el]; - if (style != null) style += ";"; else style = ""; + if (style != null) style += ";"; else style = ""; - if (!el.getAttribute('data-scrollReveal-initialized')) { - el.setAttribute('style', style + css.initial); - el.setAttribute('data-scrollReveal-initialized', true); - } + if (!el.getAttribute('data-scrollReveal-initialized')) { + el.setAttribute('style', style + css.initial); + el.setAttribute('data-scrollReveal-initialized', true); + } - if (!this.isElementInViewport(el, this.options.viewportFactor)) { - if (this.options.reset) { - el.setAttribute('style', style + css.initial + css.reset); + if (!this.isElementInViewport(el, this.options.viewportFactor)) { + if (this.options.reset) { + el.setAttribute('style', style + css.initial + css.reset); + } + return; } - return; - } - if (el.getAttribute('data-scrollReveal-complete')) return; - - if (this.isElementInViewport(el, this.options.viewportFactor)) { - el.setAttribute('style', style + css.target + css.transition); - // Without reset enabled, we can safely remove the style tag - // to prevent CSS specificy wars with authored CSS. - if (!this.options.reset) { - setTimeout(function () { - if (style != "") { - el.setAttribute('style', style); - } else { - el.removeAttribute('style'); - } - el.setAttribute('data-scrollReveal-complete',true); - }, css.totalDuration); + if (el.getAttribute('data-scrollReveal-complete')) return; + + if (this.isElementInViewport(el, this.options.viewportFactor)) { + el.setAttribute('style', style + css.target + css.transition); + // Without reset enabled, we can safely remove the style tag + // to prevent CSS specificy wars with authored CSS. + if (!this.options.reset) { + setTimeout(function () { + if (style != "") { + el.setAttribute('style', style); + } else { + el.removeAttribute('style'); + } + el.setAttribute('data-scrollReveal-complete',true); + }, css.totalDuration); + } + return; } - return; - } - }, + }, - /*=============================================================================*/ + /*=============================================================================*/ - genCSS: function (el) { - var parsed = this.parseLanguage(el), - enter, - axis; + genCSS: function (el) { + var parsed = this.parseLanguage(el), + enter, + axis; - if (parsed.enter) { + if (parsed.enter) { - if (parsed.enter == "top" || parsed.enter == "bottom") { - enter = parsed.enter; - axis = "y"; - } + if (parsed.enter == "top" || parsed.enter == "bottom") { + enter = parsed.enter; + axis = "y"; + } - if (parsed.enter == "left" || parsed.enter == "right") { - enter = parsed.enter; - axis = "x"; - } + if (parsed.enter == "left" || parsed.enter == "right") { + enter = parsed.enter; + axis = "x"; + } - } else { + } else { - if (this.options.enter == "top" || this.options.enter == "bottom") { - enter = this.options.enter - axis = "y"; - } + if (this.options.enter == "top" || this.options.enter == "bottom") { + enter = this.options.enter + axis = "y"; + } - if (this.options.enter == "left" || this.options.enter == "right") { - enter = this.options.enter - axis = "x"; + if (this.options.enter == "left" || this.options.enter == "right") { + enter = this.options.enter + axis = "x"; + } } - } -// After all values are parsed, let’s make sure our our -// pixel distance is negative for top and left entrances. -// -// ie. "move 25px from top" starts at 'top: -25px' in CSS. + // After all values are parsed, let’s make sure our our + // pixel distance is negative for top and left entrances. + // + // ie. "move 25px from top" starts at 'top: -25px' in CSS. - if (enter == "top" || enter == "left") { - if (!typeof parsed.move == "undefined") { - parsed.move = "-" + parsed.move; - } - else { - parsed.move = "-" + this.options.move; + if (enter == "top" || enter == "left") { + if (!typeof parsed.move == "undefined") { + parsed.move = "-" + parsed.move; + } + else { + parsed.move = "-" + this.options.move; + } } - } - var dist = parsed.move || this.options.move, - dur = parsed.over || this.options.over, - delay = parsed.after || this.options.after, - easing = parsed.easing || this.options.easing; - - var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + - "transition: all " + dur + " " + easing + " " + delay + ";" + - "-webkit-perspective: 1000;" + - "-webkit-backface-visibility: hidden;"; - -// The same as transition, but removing the delay for elements fading out. - var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + - "transition: all " + dur + " " + easing + " 0s;" + - "-webkit-perspective: 1000;" + - "-webkit-backface-visibility: hidden;"; - - var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + - "transform: translate" + axis + "(" + dist + ");" + - "opacity: 0;"; - - var target = "-webkit-transform: translate" + axis + "(0);" + - "transform: translate" + axis + "(0);" + - "opacity: 1;"; - return { - transition: transition, - initial: initial, - target: target, - reset: reset, - totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) - }; - }, - - getViewportH : function () { - var client = this.docElem['clientHeight'], - inner = window['innerHeight']; - - return (client < inner) ? inner : client; - }, - - getOffset : function(el) { - var offsetTop = 0, - offsetLeft = 0; - - do { - if (!isNaN(el.offsetTop)) { - offsetTop += el.offsetTop; - } - if (!isNaN(el.offsetLeft)) { - offsetLeft += el.offsetLeft; - } - } while (el = el.offsetParent) + var dist = parsed.move || this.options.move, + dur = parsed.over || this.options.over, + delay = parsed.after || this.options.after, + easing = parsed.easing || this.options.easing; + + var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + + "transition: all " + dur + " " + easing + " " + delay + ";" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + + // The same as transition, but removing the delay for elements fading out. + var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + + "transition: all " + dur + " " + easing + " 0s;" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + reset: reset, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + getViewportH : function () { + var client = this.docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + }, + + getOffset : function(el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) - return { - top: offsetTop, - left: offsetLeft - } - }, - - isElementInViewport : function(el, h) { - var scrolled = window.pageYOffset, - viewed = scrolled + this.getViewportH(), - elH = el.offsetHeight, - elTop = this.getOffset(el).top, - elBottom = elTop + elH, - h = h || 0; - - return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - }, - - extend: function (a, b){ - for (var key in b) { - if (b.hasOwnProperty(key)) { - a[key] = b[key]; + return { + top: offsetTop, + left: offsetLeft } + }, + + isElementInViewport : function(el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + this.getViewportH(), + elH = el.offsetHeight, + elTop = this.getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + }, + + extend: function (a, b){ + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; } - return a; - } -}; // end scrollReveal.prototype + }; // end scrollReveal.prototype + + return scrollReveal; +})(window); return scrollReveal; diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index 857cb3fc..738a48db 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){function t(t){this.docElem=window.document.documentElement,this.options=this.extend(this.defaults,t),1==this.options.init&&this.init()}return t.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var t=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(e){t.update(e)});var e=function(){t.scrolled||(t.scrolled=!0,setTimeout(function(){t._scrollPage()},60))},i=function(){function e(){t._scrollPage(),t.resizeTimeout=null}t.resizeTimeout&&clearTimeout(t.resizeTimeout),t.resizeTimeout=setTimeout(e,200)};window.addEventListener("scroll",e,!1),window.addEventListener("resize",i,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=t.getAttribute("style");return null!=i?i+=";":i="",t.getAttribute("data-scrollReveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scrollReveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scrollReveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scrollReveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+n+" "+a+" "+s+";transition: all "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+n+" "+a+" 0s;transition: all "+n+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var t=this.docElem.clientHeight,e=window.innerHeight;return e>t?e:t},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(t,e){var i=window.pageYOffset,o=i+this.getViewportH(),r=t.offsetHeight,n=this.getOffset(t).top,s=n+r,e=e||0;return o>=n+r*e&&s>=i},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},t}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scrollReveal]")),this.elems.forEach(function(t){e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scrollreveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){this.styleBank[t]||(this.styleBank[t]=t.getAttribute("style"));var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scrollReveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scrollReveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scrollReveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scrollReveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var s=o.move||this.options.move,r=o.over||this.options.over,n=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+r+" "+a+" "+n+";transition: all "+r+" "+a+" "+n+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+r+" "+a+" 0s;transition: all "+r+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+s+");transform: translate"+i+"("+s+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(r)+parseFloat(n))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,s=o+this.getViewportH(),r=e.offsetHeight,n=this.getOffset(e).top,a=n+r,i=i||0;return s>=n+r*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file diff --git a/package.json b/package.json index 5815f80c..c4841d72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.0.4", + "version": "0.1.0", "description": "Declarative on-scroll reveal animations", "main": "scrollReveal.js", "directories": { diff --git a/scrollReveal.js b/scrollReveal.js index b39ebee7..4f3de732 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -4,7 +4,7 @@ ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.0.4 + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.0 _/ | |__/ @@ -19,336 +19,351 @@ =============================================================================*/ -/*! scrollReveal.js v0.0.4 (c) 2014 Julian Lloyd | MIT license */ +/*! scrollReveal.js v0.1.0 (c) 2014 Julian Lloyd | MIT license */ /*===========================================================================*/ -function scrollReveal(options) { - this.docElem = window.document.documentElement; - this.options = this.extend(this.defaults, options); +window.scrollReveal = (function (window) { - if (this.options.init == true) this.init(); -} + 'use strict'; -scrollReveal.prototype = { + function scrollReveal(options) { - defaults: { - after: '0s', - enter: 'bottom', - move: '24px', - over: '0.66s', - easing: 'ease-in-out', + this.docElem = window.document.documentElement; + this.options = this.extend(this.defaults, options); + this.styleBank = []; -// if 0, the element is considered in the viewport as soon as it enters -// if 1, the element is considered in the viewport when it's fully visible - viewportFactor: 0.33, - -// if false, animations occur only once -// if true, animations occur each time an element enters the viewport - reset: false, - -// if true, scrollReveal.init() is automaticaly called upon instantiation - init: true - }, - - /*=============================================================================*/ - - init: function () { + if (this.options.init == true) this.init(); + } - this.scrolled = false; + scrollReveal.prototype = { - var self = this; + defaults: { + after: '0s', + enter: 'bottom', + move: '24px', + over: '0.66s', + easing: 'ease-in-out', -// Check DOM for the data-scrollReveal attribute -// and initialize all found elements. - this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); - this.elems.forEach(function (el, i) { - self.update(el); - }); + // if 0, the element is considered in the viewport as soon as it enters + // if 1, the element is considered in the viewport when it's fully visible + viewportFactor: 0.33, - var scrollHandler = function () { - if (!self.scrolled) { - self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); - } - }; + // if false, animations occur only once + // if true, animations occur each time an element enters the viewport + reset: false, - var resizeHandler = function () { + // if true, scrollReveal.init() is automaticaly called upon instantiation + init: true + }, - // If we’re still waiting for settimeout, reset the timer. - if (self.resizeTimeout) { - clearTimeout(self.resizeTimeout); - } - function delayed() { - self._scrollPage(); - self.resizeTimeout = null; - } - self.resizeTimeout = setTimeout(delayed, 200); - }; + /*=============================================================================*/ - window.addEventListener('scroll', scrollHandler, false); - window.addEventListener('resize', resizeHandler, false); - }, + init: function () { - /*=============================================================================*/ + this.scrolled = false; - _scrollPage: function () { var self = this; + // Check DOM for the data-scrollReveal attribute + // and initialize all found elements. + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scrollReveal]')); this.elems.forEach(function (el, i) { self.update(el); }); - this.scrolled = false; - }, - /*=============================================================================*/ + var scrollHandler = function () { + if (!self.scrolled) { + self.scrolled = true; + setTimeout(function () { + self._scrollPage(); + }, 60); + } + }; - parseLanguage: function (el) { + var resizeHandler = function () { -// Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), - parsed = {}; + // If we’re still waiting for settimeout, reset the timer. + if (self.resizeTimeout) { + clearTimeout(self.resizeTimeout); + } + function delayed() { + self._scrollPage(); + self.resizeTimeout = null; + } + self.resizeTimeout = setTimeout(delayed, 200); + }; - function filter (words) { - var ret = [], + window.addEventListener('scroll', scrollHandler, false); + window.addEventListener('resize', resizeHandler, false); + }, - blacklist = [ - "from", - "the", - "and", - "then", - "but", - "with" - ]; + /*=============================================================================*/ - words.forEach(function (word, i) { - if (blacklist.indexOf(word) > -1) { - return; - } - ret.push(word); - }); + _scrollPage: function () { + var self = this; - return ret; - } + this.elems.forEach(function (el, i) { + self.update(el); + }); + this.scrolled = false; + }, - words = filter(words); + /*=============================================================================*/ - words.forEach(function (word, i) { + parseLanguage: function (el) { - switch (word) { - case "enter": - parsed.enter = words[i + 1]; - return; + // Splits on a sequence of one or more commas or spaces. + var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + parsed = {}; - case "after": - parsed.after = words[i + 1]; - return; + function filter (words) { + var ret = [], - case "wait": - parsed.after = words[i + 1]; - return; + blacklist = [ + "from", + "the", + "and", + "then", + "but", + "with" + ]; - case "move": - parsed.move = words[i + 1]; - return; + words.forEach(function (word, i) { + if (blacklist.indexOf(word) > -1) { + return; + } + ret.push(word); + }); - case "ease": - parsed.move = words[i + 1]; - parsed.ease = "ease"; - return; + return ret; + } - case "ease-in": - parsed.move = words[i + 1]; - parsed.easing = "ease-in"; - return; + words = filter(words); - case "ease-in-out": - parsed.move = words[i + 1]; - parsed.easing = "ease-in-out"; - return; + words.forEach(function (word, i) { - case "ease-out": - parsed.move = words[i + 1]; - parsed.easing = "ease-out"; - return; + switch (word) { + case "enter": + parsed.enter = words[i + 1]; + return; + + case "after": + parsed.after = words[i + 1]; + return; + + case "wait": + parsed.after = words[i + 1]; + return; + + case "move": + parsed.move = words[i + 1]; + return; + + case "ease": + parsed.move = words[i + 1]; + parsed.ease = "ease"; + return; + + case "ease-in": + parsed.move = words[i + 1]; + parsed.easing = "ease-in"; + return; + + case "ease-in-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-in-out"; + return; + + case "ease-out": + parsed.move = words[i + 1]; + parsed.easing = "ease-out"; + return; + + case "over": + parsed.over = words[i + 1]; + return; + + default: + return; + } + }); - case "over": - parsed.over = words[i + 1]; - return; + return parsed; + }, - default: - return; - } - }); - return parsed; - }, + /*=============================================================================*/ + update: function (el) { - /*=============================================================================*/ + // Capture original style attribute + if (!this.styleBank[el]) { + this.styleBank[el] = el.getAttribute('style'); + } - update: function (el) { - var css = this.genCSS(el); - var style = el.getAttribute('style'); + var css = this.genCSS(el); + var style = this.styleBank[el]; - if (style != null) style += ";"; else style = ""; + if (style != null) style += ";"; else style = ""; - if (!el.getAttribute('data-scrollReveal-initialized')) { - el.setAttribute('style', style + css.initial); - el.setAttribute('data-scrollReveal-initialized', true); - } + if (!el.getAttribute('data-scrollReveal-initialized')) { + el.setAttribute('style', style + css.initial); + el.setAttribute('data-scrollReveal-initialized', true); + } - if (!this.isElementInViewport(el, this.options.viewportFactor)) { - if (this.options.reset) { - el.setAttribute('style', style + css.initial + css.reset); + if (!this.isElementInViewport(el, this.options.viewportFactor)) { + if (this.options.reset) { + el.setAttribute('style', style + css.initial + css.reset); + } + return; } - return; - } - if (el.getAttribute('data-scrollReveal-complete')) return; - - if (this.isElementInViewport(el, this.options.viewportFactor)) { - el.setAttribute('style', style + css.target + css.transition); - // Without reset enabled, we can safely remove the style tag - // to prevent CSS specificy wars with authored CSS. - if (!this.options.reset) { - setTimeout(function () { - if (style != "") { - el.setAttribute('style', style); - } else { - el.removeAttribute('style'); - } - el.setAttribute('data-scrollReveal-complete',true); - }, css.totalDuration); + if (el.getAttribute('data-scrollReveal-complete')) return; + + if (this.isElementInViewport(el, this.options.viewportFactor)) { + el.setAttribute('style', style + css.target + css.transition); + // Without reset enabled, we can safely remove the style tag + // to prevent CSS specificy wars with authored CSS. + if (!this.options.reset) { + setTimeout(function () { + if (style != "") { + el.setAttribute('style', style); + } else { + el.removeAttribute('style'); + } + el.setAttribute('data-scrollReveal-complete',true); + }, css.totalDuration); + } + return; } - return; - } - }, + }, - /*=============================================================================*/ + /*=============================================================================*/ - genCSS: function (el) { - var parsed = this.parseLanguage(el), - enter, - axis; + genCSS: function (el) { + var parsed = this.parseLanguage(el), + enter, + axis; - if (parsed.enter) { + if (parsed.enter) { - if (parsed.enter == "top" || parsed.enter == "bottom") { - enter = parsed.enter; - axis = "y"; - } + if (parsed.enter == "top" || parsed.enter == "bottom") { + enter = parsed.enter; + axis = "y"; + } - if (parsed.enter == "left" || parsed.enter == "right") { - enter = parsed.enter; - axis = "x"; - } + if (parsed.enter == "left" || parsed.enter == "right") { + enter = parsed.enter; + axis = "x"; + } - } else { + } else { - if (this.options.enter == "top" || this.options.enter == "bottom") { - enter = this.options.enter - axis = "y"; - } + if (this.options.enter == "top" || this.options.enter == "bottom") { + enter = this.options.enter + axis = "y"; + } - if (this.options.enter == "left" || this.options.enter == "right") { - enter = this.options.enter - axis = "x"; + if (this.options.enter == "left" || this.options.enter == "right") { + enter = this.options.enter + axis = "x"; + } } - } -// After all values are parsed, let’s make sure our our -// pixel distance is negative for top and left entrances. -// -// ie. "move 25px from top" starts at 'top: -25px' in CSS. + // After all values are parsed, let’s make sure our our + // pixel distance is negative for top and left entrances. + // + // ie. "move 25px from top" starts at 'top: -25px' in CSS. - if (enter == "top" || enter == "left") { - if (!typeof parsed.move == "undefined") { - parsed.move = "-" + parsed.move; - } - else { - parsed.move = "-" + this.options.move; + if (enter == "top" || enter == "left") { + if (!typeof parsed.move == "undefined") { + parsed.move = "-" + parsed.move; + } + else { + parsed.move = "-" + this.options.move; + } } - } - var dist = parsed.move || this.options.move, - dur = parsed.over || this.options.over, - delay = parsed.after || this.options.after, - easing = parsed.easing || this.options.easing; - - var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + - "transition: all " + dur + " " + easing + " " + delay + ";" + - "-webkit-perspective: 1000;" + - "-webkit-backface-visibility: hidden;"; - -// The same as transition, but removing the delay for elements fading out. - var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + - "transition: all " + dur + " " + easing + " 0s;" + - "-webkit-perspective: 1000;" + - "-webkit-backface-visibility: hidden;"; - - var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + - "transform: translate" + axis + "(" + dist + ");" + - "opacity: 0;"; - - var target = "-webkit-transform: translate" + axis + "(0);" + - "transform: translate" + axis + "(0);" + - "opacity: 1;"; - return { - transition: transition, - initial: initial, - target: target, - reset: reset, - totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) - }; - }, - - getViewportH : function () { - var client = this.docElem['clientHeight'], - inner = window['innerHeight']; - - return (client < inner) ? inner : client; - }, - - getOffset : function(el) { - var offsetTop = 0, - offsetLeft = 0; - - do { - if (!isNaN(el.offsetTop)) { - offsetTop += el.offsetTop; - } - if (!isNaN(el.offsetLeft)) { - offsetLeft += el.offsetLeft; - } - } while (el = el.offsetParent) + var dist = parsed.move || this.options.move, + dur = parsed.over || this.options.over, + delay = parsed.after || this.options.after, + easing = parsed.easing || this.options.easing; + + var transition = "-webkit-transition: all " + dur + " " + easing + " " + delay + ";" + + "transition: all " + dur + " " + easing + " " + delay + ";" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + + // The same as transition, but removing the delay for elements fading out. + var reset = "-webkit-transition: all " + dur + " " + easing + " 0s;" + + "transition: all " + dur + " " + easing + " 0s;" + + "-webkit-perspective: 1000;" + + "-webkit-backface-visibility: hidden;"; + + var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + + "transform: translate" + axis + "(" + dist + ");" + + "opacity: 0;"; + + var target = "-webkit-transform: translate" + axis + "(0);" + + "transform: translate" + axis + "(0);" + + "opacity: 1;"; + return { + transition: transition, + initial: initial, + target: target, + reset: reset, + totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) + }; + }, + + getViewportH : function () { + var client = this.docElem['clientHeight'], + inner = window['innerHeight']; + + return (client < inner) ? inner : client; + }, + + getOffset : function(el) { + var offsetTop = 0, + offsetLeft = 0; + + do { + if (!isNaN(el.offsetTop)) { + offsetTop += el.offsetTop; + } + if (!isNaN(el.offsetLeft)) { + offsetLeft += el.offsetLeft; + } + } while (el = el.offsetParent) - return { - top: offsetTop, - left: offsetLeft - } - }, - - isElementInViewport : function(el, h) { - var scrolled = window.pageYOffset, - viewed = scrolled + this.getViewportH(), - elH = el.offsetHeight, - elTop = this.getOffset(el).top, - elBottom = elTop + elH, - h = h || 0; - - return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - }, - - extend: function (a, b){ - for (var key in b) { - if (b.hasOwnProperty(key)) { - a[key] = b[key]; + return { + top: offsetTop, + left: offsetLeft } + }, + + isElementInViewport : function(el, h) { + var scrolled = window.pageYOffset, + viewed = scrolled + this.getViewportH(), + elH = el.offsetHeight, + elTop = this.getOffset(el).top, + elBottom = elTop + elH, + h = h || 0; + + return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; + }, + + extend: function (a, b){ + for (var key in b) { + if (b.hasOwnProperty(key)) { + a[key] = b[key]; + } + } + return a; } - return a; - } -}; // end scrollReveal.prototype + }; // end scrollReveal.prototype + + return scrollReveal; +})(window); From 2a6e6ee43febab49f7ea0ca1a2f1ad7e34f13ba9 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 5 Mar 2014 14:55:57 -0800 Subject: [PATCH 51/79] Revise bowe.json for v0.1.0 --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 75a845ca..6dd80219 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.0.4", + "version": "0.1.0", "homepage": "https://github.com/julianlloyd/scrollReveal.js", "authors": [ "Julian Lloyd " From c053be6de2a0f6c32f8be14f14465e156a281fc6 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 5 Mar 2014 14:57:41 -0800 Subject: [PATCH 52/79] Revise bower.json for v0.1.0 --- bower.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 6dd80219..4a9286d1 100644 --- a/bower.json +++ b/bower.json @@ -9,12 +9,13 @@ "main": ["scrollReveal.js"], "keywords": [ "scrollReveal", + "scroll", + "reveal", + "scroll-reveal" "animation", "CSS", "transition", - "JavaScript", - "scroll", - "reveal" + "JavaScript" ], "license": "MIT", "ignore": [ From fafca4b4919bdc02024dd67cb811dcb1650963ae Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 5 Mar 2014 15:38:38 -0800 Subject: [PATCH 53/79] Update data attribute v0.1.0 --- dist/scrollReveal.js | 12 ++++++------ dist/scrollReveal.min.js | 2 +- scrollReveal.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index 0758f306..7abf4fde 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -79,7 +79,7 @@ window.scrollReveal = (function (window) { // Check DOM for the data-scrollReveal attribute // and initialize all found elements. - this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scrollReveal]')); + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); this.elems.forEach(function (el, i) { self.update(el); }); @@ -126,7 +126,7 @@ window.scrollReveal = (function (window) { parseLanguage: function (el) { // Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), parsed = {}; function filter (words) { @@ -219,9 +219,9 @@ window.scrollReveal = (function (window) { if (style != null) style += ";"; else style = ""; - if (!el.getAttribute('data-scrollReveal-initialized')) { + if (!el.getAttribute('data-scroll-reveal-initialized')) { el.setAttribute('style', style + css.initial); - el.setAttribute('data-scrollReveal-initialized', true); + el.setAttribute('data-scroll-reveal-initialized', true); } if (!this.isElementInViewport(el, this.options.viewportFactor)) { @@ -231,7 +231,7 @@ window.scrollReveal = (function (window) { return; } - if (el.getAttribute('data-scrollReveal-complete')) return; + if (el.getAttribute('data-scroll-reveal-complete')) return; if (this.isElementInViewport(el, this.options.viewportFactor)) { el.setAttribute('style', style + css.target + css.transition); @@ -244,7 +244,7 @@ window.scrollReveal = (function (window) { } else { el.removeAttribute('style'); } - el.setAttribute('data-scrollReveal-complete',true); + el.setAttribute('data-scroll-reveal-complete',true); }, css.totalDuration); } return; diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index 738a48db..dedcde6e 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scrollReveal]")),this.elems.forEach(function(t){e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scrollreveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){this.styleBank[t]||(this.styleBank[t]=t.getAttribute("style"));var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scrollReveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scrollReveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scrollReveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scrollReveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var s=o.move||this.options.move,r=o.over||this.options.over,n=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+r+" "+a+" "+n+";transition: all "+r+" "+a+" "+n+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+r+" "+a+" 0s;transition: all "+r+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+s+");transform: translate"+i+"("+s+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(r)+parseFloat(n))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,s=o+this.getViewportH(),r=e.offsetHeight,n=this.getOffset(e).top,a=n+r,i=i||0;return s>=n+r*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){this.styleBank[t]||(this.styleBank[t]=t.getAttribute("style"));var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var r=o.move||this.options.move,s=o.over||this.options.over,n=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+s+" "+a+" "+n+";transition: all "+s+" "+a+" "+n+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+s+" "+a+" 0s;transition: all "+s+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(s)+parseFloat(n))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),s=e.offsetHeight,n=this.getOffset(e).top,a=n+s,i=i||0;return r>=n+s*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file diff --git a/scrollReveal.js b/scrollReveal.js index 4f3de732..a9964018 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -68,7 +68,7 @@ window.scrollReveal = (function (window) { // Check DOM for the data-scrollReveal attribute // and initialize all found elements. - this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scrollReveal]')); + this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); this.elems.forEach(function (el, i) { self.update(el); }); @@ -115,7 +115,7 @@ window.scrollReveal = (function (window) { parseLanguage: function (el) { // Splits on a sequence of one or more commas or spaces. - var words = el.getAttribute('data-scrollreveal').split(/[, ]+/), + var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), parsed = {}; function filter (words) { @@ -208,9 +208,9 @@ window.scrollReveal = (function (window) { if (style != null) style += ";"; else style = ""; - if (!el.getAttribute('data-scrollReveal-initialized')) { + if (!el.getAttribute('data-scroll-reveal-initialized')) { el.setAttribute('style', style + css.initial); - el.setAttribute('data-scrollReveal-initialized', true); + el.setAttribute('data-scroll-reveal-initialized', true); } if (!this.isElementInViewport(el, this.options.viewportFactor)) { @@ -220,7 +220,7 @@ window.scrollReveal = (function (window) { return; } - if (el.getAttribute('data-scrollReveal-complete')) return; + if (el.getAttribute('data-scroll-reveal-complete')) return; if (this.isElementInViewport(el, this.options.viewportFactor)) { el.setAttribute('style', style + css.target + css.transition); @@ -233,7 +233,7 @@ window.scrollReveal = (function (window) { } else { el.removeAttribute('style'); } - el.setAttribute('data-scrollReveal-complete',true); + el.setAttribute('data-scroll-reveal-complete',true); }, css.totalDuration); } return; From c648587406d8241f37ecff7d03fd957725b66fcd Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 5 Mar 2014 16:05:35 -0800 Subject: [PATCH 54/79] Release v0.1.0 Fixes #23 (for serious) --- dist/scrollReveal.js | 11 ++++++----- dist/scrollReveal.min.js | 2 +- scrollReveal.js | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index 7abf4fde..bb405d43 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -81,6 +81,12 @@ window.scrollReveal = (function (window) { // and initialize all found elements. this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); this.elems.forEach(function (el, i) { + + // Capture original style attribute + if (!self.styleBank[el]) { + self.styleBank[el] = el.getAttribute('style'); + } + self.update(el); }); @@ -209,11 +215,6 @@ window.scrollReveal = (function (window) { update: function (el) { - // Capture original style attribute - if (!this.styleBank[el]) { - this.styleBank[el] = el.getAttribute('style'); - } - var css = this.genCSS(el); var style = this.styleBank[el]; diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index dedcde6e..e2aba664 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){this.styleBank[t]||(this.styleBank[t]=t.getAttribute("style"));var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var r=o.move||this.options.move,s=o.over||this.options.over,n=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+s+" "+a+" "+n+";transition: all "+s+" "+a+" "+n+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+s+" "+a+" 0s;transition: all "+s+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(s)+parseFloat(n))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),s=e.offsetHeight,n=this.getOffset(e).top,a=n+s,i=i||0;return r>=n+s*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+n+" "+a+" "+s+";transition: all "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+n+" "+a+" 0s;transition: all "+n+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file diff --git a/scrollReveal.js b/scrollReveal.js index a9964018..4644f80c 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -70,6 +70,12 @@ window.scrollReveal = (function (window) { // and initialize all found elements. this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); this.elems.forEach(function (el, i) { + + // Capture original style attribute + if (!self.styleBank[el]) { + self.styleBank[el] = el.getAttribute('style'); + } + self.update(el); }); @@ -198,11 +204,6 @@ window.scrollReveal = (function (window) { update: function (el) { - // Capture original style attribute - if (!this.styleBank[el]) { - this.styleBank[el] = el.getAttribute('style'); - } - var css = this.genCSS(el); var style = this.styleBank[el]; From c2080432f7ce1bdd7efc332c8e3ddc70930e77b2 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 6 Mar 2014 03:29:35 -0800 Subject: [PATCH 55/79] Fix malformed bower.json. Resolves #29 --- bower.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bower.json b/bower.json index 4a9286d1..2192ab99 100644 --- a/bower.json +++ b/bower.json @@ -11,7 +11,6 @@ "scrollReveal", "scroll", "reveal", - "scroll-reveal" "animation", "CSS", "transition", From a44792231637b2501587ff969e834e86e5692c3b Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 6 Mar 2014 10:55:56 -0800 Subject: [PATCH 56/79] release scrollReveal.js v0.1.1 Fixes #31 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- dist/scrollReveal.js | 2 +- dist/scrollReveal.min.js | 2 +- package.json | 2 +- scrollReveal.js | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e085dbbb..427db126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ###### scrollReveal.js Changelog +### v0.1.1 march 6th, 2014 + +* Fixed a serious bug with `enter top` and `enter left` not correctly recognizing the pixel distance declared in awith the `move` keyword. **Fixes #31** (Thanks for catching this [Sherban](https://github.com/sherban1988)!) + ### v0.1.0 march 5th, 2014 * scrollReveal.js now has a `dist` folder containing the AMD/CommonJS compatibile library. diff --git a/bower.json b/bower.json index 2192ab99..77fd5a85 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/julianlloyd/scrollReveal.js", "authors": [ "Julian Lloyd " diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index bb405d43..83c1e034 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -290,7 +290,7 @@ window.scrollReveal = (function (window) { // ie. "move 25px from top" starts at 'top: -25px' in CSS. if (enter == "top" || enter == "left") { - if (!typeof parsed.move == "undefined") { + if (parsed.move) { parsed.move = "-" + parsed.move; } else { diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index e2aba664..f0d3a1bd 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move="-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+n+" "+a+" "+s+";transition: all "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+n+" "+a+" 0s;transition: all "+n+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: all "+n+" "+a+" "+s+";transition: all "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: all "+n+" "+a+" 0s;transition: all "+n+" "+a+" 0s;-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file diff --git a/package.json b/package.json index c4841d72..045c81ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.1.0", + "version": "0.1.1", "description": "Declarative on-scroll reveal animations", "main": "scrollReveal.js", "directories": { diff --git a/scrollReveal.js b/scrollReveal.js index 4644f80c..5b69b8c9 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -279,7 +279,7 @@ window.scrollReveal = (function (window) { // ie. "move 25px from top" starts at 'top: -25px' in CSS. if (enter == "top" || enter == "left") { - if (!typeof parsed.move == "undefined") { + if (parsed.move) { parsed.move = "-" + parsed.move; } else { From 696234eefc400984f373c88827c0ba4d6711f53c Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 6 Mar 2014 11:08:50 -0800 Subject: [PATCH 57/79] Update CHANGELOG for v0.1.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 427db126..be8f479f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### v0.1.1 march 6th, 2014 -* Fixed a serious bug with `enter top` and `enter left` not correctly recognizing the pixel distance declared in awith the `move` keyword. **Fixes #31** (Thanks for catching this [Sherban](https://github.com/sherban1988)!) +* Fixed a serious bug with `enter top` and `enter left` not correctly recognizing the pixel distance declared with the `move` keyword. **Fixes #13 and #31** (Thanks for catching this [Sherban](https://github.com/sherban1988) and [Danycerone](https://github.com/damycerone).) ### v0.1.0 march 5th, 2014 From 7181f20f4557c1fef0b26abb28d4dd391111459b Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Fri, 7 Mar 2014 03:06:26 -0800 Subject: [PATCH 58/79] Update README with new demo URL --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2c52f915..ed8131e9 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ A simple way to create and maintain how elements fade in, triggered when they en [![scrollReveal version](https://badge.fury.io/gh/julianlloyd%2FscrollReveal.js.png)](http://badge.fury.io/gh/julianlloyd%2FscrollReveal.js) *** -####**[→ View Demo ←](http://julianlloyd.me/scrollreveal)** +####**[→ View Demo ←](http://scrollrevealjs.com/)** *** Installation ------------ > **Disclaimer:** scrollReveal.js is in early development, and breaking changes will likely occur in future updates. Before updating, please refer to the [CHANGELOG](https://github.com/julianlloyd/scrollReveal.js/blob/master/CHANGELOG.md) for details. #### Download -[scrollReveal.js ](https://github.com/julianlloyd/scrollReveal.js/archive/master.zip) +[master.zip](https://github.com/julianlloyd/scrollReveal.js/archive/master.zip) #### GitHub `git clone https://github.com/julianlloyd/scrollReveal.js.git` @@ -19,11 +19,11 @@ Installation `bower install scrollReveal.js` *** -Once you have a copy of `scrollReveal.js`, place it in your JavaScript folder, and include the following JavaScript just before the closing `` tag. +Once you have a copy of `scrollReveal.min.js`, place it in your JavaScript folder and include the following JavaScript just before the closing `` tag. ```html - + + ``` -By default `init` is set to `true`, meaning `scrollReveal.init()` fires on instantiation. (This registers DOM elements and prepares them to reveal)

You may want to set `init` to `false` if you’re working with templates or other generated content, letting you control when `scrollReveal.init()` is first called.

You can also call this method any time afterwards to re-check all elements in the DOM for `data-scroll-reveal` attributes. #### Generated HTML -You may have dynamically generated HTML in your use case, (AJAX, templates, other JavaScript libraries, etc.,) so as mentioned above, the scrollReveal object has the `init()` helper method that checks for new elements in the DOM. + +The `scrollReveal.init()` method to checks for any new elements in the DOM. By default, this method fires on instantiation, but by changing amending our config object with `init: false`, one can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) + +It’s worth nothing, you can also call this method at any time to re-check the DOM for all elements with `data-scroll-reveal` attributes. *Example:* ```html From b758600d14ae6156d30fad5df623d00d582e63ee Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Mar 2014 12:14:32 -0700 Subject: [PATCH 69/79] Revise README for v0.1.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd632e5c..752b9b8a 100644 --- a/README.md +++ b/README.md @@ -152,9 +152,9 @@ You can pass an object to the constructor with your desired default configuratio #### Generated HTML -The `scrollReveal.init()` method to checks for any new elements in the DOM. By default, this method fires on instantiation, but by changing amending our config object with `init: false`, one can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) +The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes your reveal animations on them. By default, this method fires on instantiation, but by changing amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) -It’s worth nothing, you can also call this method at any time to re-check the DOM for all elements with `data-scroll-reveal` attributes. +^**Note:** It’s worth nothing, you can also call this method at any time to re-check the DOM. *Example:* ```html From c5ef484b3bcacae2af7a30ade97b2735c8d912e9 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Mar 2014 12:15:27 -0700 Subject: [PATCH 70/79] Revise README for v0.1.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 752b9b8a..e2a87067 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ You can pass an object to the constructor with your desired default configuratio #### Generated HTML -The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes your reveal animations on them. By default, this method fires on instantiation, but by changing amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) +The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes their reveal animations. By default, this method fires on instantiation, but by changing amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) ^**Note:** It’s worth nothing, you can also call this method at any time to re-check the DOM. From aa6eb2da451e2320253ee1001a9b823296a922c4 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Mar 2014 12:16:16 -0700 Subject: [PATCH 71/79] Revise README for v0.1.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2a87067..1d4e86b7 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ You can pass an object to the constructor with your desired default configuratio #### Generated HTML -The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes their reveal animations. By default, this method fires on instantiation, but by changing amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) +The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes their reveal animations. By default, this method fires on instantiation, but by amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) ^**Note:** It’s worth nothing, you can also call this method at any time to re-check the DOM. From dc43e91ed317c7ed308ba734264cc2e9efea3838 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Mar 2014 12:16:55 -0700 Subject: [PATCH 72/79] Revise README for v0.1.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d4e86b7..56ffa93e 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ You can pass an object to the constructor with your desired default configuratio The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes their reveal animations. By default, this method fires on instantiation, but by amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) -^**Note:** It’s worth nothing, you can also call this method at any time to re-check the DOM. +>**Note:** It’s worth nothing, you can also call this method at any time to re-check the DOM. *Example:* ```html From df0703c3e8c255a687a36dd317f1ce5611f8ac96 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Thu, 13 Mar 2014 12:17:31 -0700 Subject: [PATCH 73/79] Revise README for v0.1.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56ffa93e..915cb8a2 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ You can pass an object to the constructor with your desired default configuratio The `scrollReveal.init()` method checks the DOM for all elements with `data-scroll-reveal` attributes, and initializes their reveal animations. By default, this method fires on instantiation, but by amending our config object with `init: false`, you can then choose when `scrollReveal.init()` is first fired. (Say, after your DOM is updated.) ->**Note:** It’s worth nothing, you can also call this method at any time to re-check the DOM. +>**Note:** It’s worth noting, you can also call this method at any time to re-check the DOM. *Example:* ```html From 5440c8dc88d7076e0a0bab4e29ee1623d5cc44b4 Mon Sep 17 00:00:00 2001 From: George Lee Date: Fri, 14 Mar 2014 17:06:50 +0000 Subject: [PATCH 74/79] Fixes bug with styleBank --- scrollReveal.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scrollReveal.js b/scrollReveal.js index ff23a166..396ea477 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -27,12 +27,15 @@ window.scrollReveal = (function (window) { 'use strict'; + + // generator (increments) for the next scroll-reveal-id + var nextId = 1; function scrollReveal(options) { this.docElem = window.document.documentElement; this.options = this.extend(this.defaults, options); - this.styleBank = []; + this.styleBank = {}; if (this.options.init == true) this.init(); } @@ -72,8 +75,13 @@ window.scrollReveal = (function (window) { this.elems.forEach(function (el, i) { // Capture original style attribute - if (!self.styleBank[el]) { - self.styleBank[el] = el.getAttribute('style'); + var id = el.getAttribute("data-scroll-reveal-id"); + if (!id) { + id = nextId++; + el.setAttribute("data-scroll-reveal-id", id); + } + if (!self.styleBank[id]) { + self.styleBank[id] = el.getAttribute('style'); } self.update(el); @@ -205,7 +213,7 @@ window.scrollReveal = (function (window) { update: function (el) { var css = this.genCSS(el); - var style = this.styleBank[el]; + var style = this.styleBank[el.getAttribute("data-scroll-reveal-id")]; if (style != null) style += ";"; else style = ""; From 9225c07c17bef7fe7a55c4aacb0ceec686271a5d Mon Sep 17 00:00:00 2001 From: Guille Paz Date: Thu, 17 Apr 2014 14:29:04 -0300 Subject: [PATCH 75/79] Decouple the scroll event from _scrollPage function using requestAnimationFrame. --- dist/scrollReveal.js | 24 ++++++++++++++++++++---- dist/scrollReveal.min.js | 2 +- scrollReveal.js | 24 ++++++++++++++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index 84e04d26..bbbbd184 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -39,6 +39,20 @@ window.scrollReveal = (function (window) { 'use strict'; + /** + * RequestAnimationFrame polyfill + * @function + * @private + */ + var requestAnimFrame = (function () { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + function (callback) { + window.setTimeout(callback, 1000 / 60); + }; + }()); + function scrollReveal(options) { this.docElem = window.document.documentElement; @@ -90,12 +104,13 @@ window.scrollReveal = (function (window) { self.update(el); }); - var scrollHandler = function () { + var scrollHandler = function (e) { + // No changing, exit if (!self.scrolled) { self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); + requestAnimFrame(function () { + self._scrollPage + }); } }; @@ -112,6 +127,7 @@ window.scrollReveal = (function (window) { self.resizeTimeout = setTimeout(delayed, 200); }; + // captureScroll window.addEventListener('scroll', scrollHandler, false); window.addEventListener('resize', resizeHandler, false); }, diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index 69b31969..8aca9518 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var i=function(){e.scrolled||(e.scrolled=!0,setTimeout(function(){e._scrollPage()},60))},o=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",i,!1),t.addEventListener("resize",o,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: -webkit-transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: -webkit-transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o||"fixed"==(e.currentStyle?e.currentStyle:t.getComputedStyle(e,null)).position},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}var i=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}();return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var o=function(){e.scrolled||(e.scrolled=!0,i(function(){e._scrollPage}))},r=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",o,!1),t.addEventListener("resize",r,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: -webkit-transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: -webkit-transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o||"fixed"==(e.currentStyle?e.currentStyle:t.getComputedStyle(e,null)).position},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file diff --git a/scrollReveal.js b/scrollReveal.js index ff23a166..7c5e6c2f 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -28,6 +28,20 @@ window.scrollReveal = (function (window) { 'use strict'; + /** + * RequestAnimationFrame polyfill + * @function + * @private + */ + var requestAnimFrame = (function () { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + function (callback) { + window.setTimeout(callback, 1000 / 60); + }; + }()); + function scrollReveal(options) { this.docElem = window.document.documentElement; @@ -79,12 +93,13 @@ window.scrollReveal = (function (window) { self.update(el); }); - var scrollHandler = function () { + var scrollHandler = function (e) { + // No changing, exit if (!self.scrolled) { self.scrolled = true; - setTimeout(function () { - self._scrollPage(); - }, 60); + requestAnimFrame(function () { + self._scrollPage + }); } }; @@ -101,6 +116,7 @@ window.scrollReveal = (function (window) { self.resizeTimeout = setTimeout(delayed, 200); }; + // captureScroll window.addEventListener('scroll', scrollHandler, false); window.addEventListener('resize', resizeHandler, false); }, From 489a2a389621c48debd0e31f5c9c52bd2caf8657 Mon Sep 17 00:00:00 2001 From: Guille Paz Date: Mon, 26 May 2014 01:00:50 -0300 Subject: [PATCH 76/79] Execute self._scrollPage function. --- scrollReveal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrollReveal.js b/scrollReveal.js index 7c5e6c2f..d42a0fe1 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -98,7 +98,7 @@ window.scrollReveal = (function (window) { if (!self.scrolled) { self.scrolled = true; requestAnimFrame(function () { - self._scrollPage + self._scrollPage(); }); } }; From 0ebb95313a3e46a16c90ef6d2c16a002cb410b8a Mon Sep 17 00:00:00 2001 From: Guille Paz Date: Mon, 26 May 2014 01:08:27 -0300 Subject: [PATCH 77/79] Fix #55 on dist version. --- dist/scrollReveal.js | 2 +- dist/scrollReveal.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index bbbbd184..3ecf5a0c 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -109,7 +109,7 @@ window.scrollReveal = (function (window) { if (!self.scrolled) { self.scrolled = true; requestAnimFrame(function () { - self._scrollPage + self._scrollPage(); }); } }; diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index 8aca9518..65d4f5ae 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}var i=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}();return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var o=function(){e.scrolled||(e.scrolled=!0,i(function(){e._scrollPage}))},r=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",o,!1),t.addEventListener("resize",r,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: -webkit-transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: -webkit-transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o||"fixed"==(e.currentStyle?e.currentStyle:t.getComputedStyle(e,null)).position},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}var i=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}();return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var o=function(){e.scrolled||(e.scrolled=!0,i(function(){e._scrollPage()}))},r=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",o,!1),t.addEventListener("resize",r,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: -webkit-transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: -webkit-transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o||"fixed"==(e.currentStyle?e.currentStyle:t.getComputedStyle(e,null)).position},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file From fc4063e60493106899a26393ba2776ace580d3b8 Mon Sep 17 00:00:00 2001 From: Guille Paz Date: Mon, 26 May 2014 01:12:36 -0300 Subject: [PATCH 78/79] Update version to 0.1.3 --- dist/scrollReveal.js | 2 +- package.json | 2 +- scrollReveal.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index 3ecf5a0c..a1bf7199 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -30,7 +30,7 @@ =============================================================================*/ -/*! scrollReveal.js v0.1.2 (c) 2014 Julian Lloyd | MIT license */ +/*! scrollReveal.js v0.1.3 (c) 2014 Julian Lloyd | MIT license */ /*===========================================================================*/ diff --git a/package.json b/package.json index 8da7c7ea..22a0f325 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.1.2", + "version": "0.1.3", "description": "Declarative on-scroll reveal animations", "main": "scrollReveal.js", "directories": { diff --git a/scrollReveal.js b/scrollReveal.js index d42a0fe1..9a37cfac 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -19,7 +19,7 @@ =============================================================================*/ -/*! scrollReveal.js v0.1.2 (c) 2014 Julian Lloyd | MIT license */ +/*! scrollReveal.js v0.1.3 (c) 2014 Julian Lloyd | MIT license */ /*===========================================================================*/ From 1e77299c624e078d29f5c5c4bfbfde2e77560c18 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Mon, 26 May 2014 17:04:42 -0700 Subject: [PATCH 79/79] =?UTF-8?q?Release=20v0.1.3=20=E2=80=93=20see=20issu?= =?UTF-8?q?es=20#33=20#38=20#48?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ bower.json | 2 +- dist/scrollReveal.js | 40 +++++++++++++++++++++++++--------------- dist/scrollReveal.min.js | 2 +- scrollReveal.js | 4 ++-- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8404d4a7..8075a473 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ###### scrollReveal.js Changelog +v0.1.3 May 26th, 2014 +------------------------- + +- Add support for customizing starting element opacity (from kierzniak, see issue [#33](https://github.com/julianlloyd/scrollReveal.js/pull/33)) +- Implement RequestAnimationFrame (from pazguille, see issue [#46](https://github.com/julianlloyd/scrollReveal.js/pull/46)) +- Refactor how `styleBank` functions (from georgelee1, see issue [#38](https://github.com/julianlloyd/scrollReveal.js/pull/38)) + + v0.1.2 March 13th, 2014 ------------------------- diff --git a/bower.json b/bower.json index 849ae058..2f86b0ca 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "scrollReveal.js", - "version": "0.1.2", + "version": "0.1.3", "homepage": "https://github.com/julianlloyd/scrollReveal.js", "authors": [ "Julian Lloyd " diff --git a/dist/scrollReveal.js b/dist/scrollReveal.js index a1bf7199..9e3bd17e 100644 --- a/dist/scrollReveal.js +++ b/dist/scrollReveal.js @@ -15,7 +15,7 @@ ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.2 + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.3 _/ | |__/ @@ -39,6 +39,9 @@ window.scrollReveal = (function (window) { 'use strict'; + // generator (increments) for the next scroll-reveal-id + var nextId = 1; + /** * RequestAnimationFrame polyfill * @function @@ -57,7 +60,7 @@ window.scrollReveal = (function (window) { this.docElem = window.document.documentElement; this.options = this.extend(this.defaults, options); - this.styleBank = []; + this.styleBank = {}; if (this.options.init == true) this.init(); } @@ -65,11 +68,12 @@ window.scrollReveal = (function (window) { scrollReveal.prototype = { defaults: { - after: '0s', - enter: 'bottom', - move: '24px', - over: '0.66s', - easing: 'ease-in-out', + after: '0s', + enter: 'bottom', + move: '24px', + over: '0.66s', + easing: 'ease-in-out', + opacity: 0, // if 0, the element is considered in the viewport as soon as it enters // if 1, the element is considered in the viewport when it's fully visible @@ -97,8 +101,13 @@ window.scrollReveal = (function (window) { this.elems.forEach(function (el, i) { // Capture original style attribute - if (!self.styleBank[el]) { - self.styleBank[el] = el.getAttribute('style'); + var id = el.getAttribute("data-scroll-reveal-id"); + if (!id) { + id = nextId++; + el.setAttribute("data-scroll-reveal-id", id); + } + if (!self.styleBank[id]) { + self.styleBank[id] = el.getAttribute('style'); } self.update(el); @@ -232,7 +241,7 @@ window.scrollReveal = (function (window) { update: function (el) { var css = this.genCSS(el); - var style = this.styleBank[el]; + var style = this.styleBank[el.getAttribute("data-scroll-reveal-id")]; if (style != null) style += ";"; else style = ""; @@ -314,10 +323,11 @@ window.scrollReveal = (function (window) { } } - var dist = parsed.move || this.options.move, - dur = parsed.over || this.options.over, - delay = parsed.after || this.options.after, - easing = parsed.easing || this.options.easing; + var dist = parsed.move || this.options.move, + dur = parsed.over || this.options.over, + delay = parsed.after || this.options.after, + easing = parsed.easing || this.options.easing, + opacity = parsed.opacity || this.options.opacity; var transition = "-webkit-transition: -webkit-transform " + dur + " " + easing + " " + delay + ", opacity " + dur + " " + easing + " " + delay + ";" + "transition: transform " + dur + " " + easing + " " + delay + ", opacity " + dur + " " + easing + " " + delay + ";" + @@ -332,7 +342,7 @@ window.scrollReveal = (function (window) { var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + "transform: translate" + axis + "(" + dist + ");" + - "opacity: 0;"; + "opacity: " + opacity + ";"; var target = "-webkit-transform: translate" + axis + "(0);" + "transform: translate" + axis + "(0);" + diff --git a/dist/scrollReveal.min.js b/dist/scrollReveal.min.js index 65d4f5ae..2e4e3138 100644 --- a/dist/scrollReveal.min.js +++ b/dist/scrollReveal.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank=[],1==this.options.init&&this.init()}var i=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}();return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){e.styleBank[t]||(e.styleBank[t]=t.getAttribute("style")),e.update(t)});var o=function(){e.scrolled||(e.scrolled=!0,i(function(){e._scrollPage()}))},r=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",o,!1),t.addEventListener("resize",r,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l="-webkit-transition: -webkit-transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",u="-webkit-transition: -webkit-transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: 0;",f="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:l,initial:c,target:f,reset:u,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o||"fixed"==(e.currentStyle?e.currentStyle:t.getComputedStyle(e,null)).position},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.scrollReveal=e()}(this,function(){return window.scrollReveal=function(t){"use strict";function e(e){this.docElem=t.document.documentElement,this.options=this.extend(this.defaults,e),this.styleBank={},1==this.options.init&&this.init()}var i=1,o=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}();return e.prototype={defaults:{after:"0s",enter:"bottom",move:"24px",over:"0.66s",easing:"ease-in-out",opacity:0,viewportFactor:.33,reset:!1,init:!0},init:function(){this.scrolled=!1;var e=this;this.elems=Array.prototype.slice.call(this.docElem.querySelectorAll("[data-scroll-reveal]")),this.elems.forEach(function(t){var o=t.getAttribute("data-scroll-reveal-id");o||(o=i++,t.setAttribute("data-scroll-reveal-id",o)),e.styleBank[o]||(e.styleBank[o]=t.getAttribute("style")),e.update(t)});var r=function(){e.scrolled||(e.scrolled=!0,o(function(){e._scrollPage()}))},n=function(){function t(){e._scrollPage(),e.resizeTimeout=null}e.resizeTimeout&&clearTimeout(e.resizeTimeout),e.resizeTimeout=setTimeout(t,200)};t.addEventListener("scroll",r,!1),t.addEventListener("resize",n,!1)},_scrollPage:function(){var t=this;this.elems.forEach(function(e){t.update(e)}),this.scrolled=!1},parseLanguage:function(t){function e(t){var e=[],i=["from","the","and","then","but","with"];return t.forEach(function(t){i.indexOf(t)>-1||e.push(t)}),e}var i=t.getAttribute("data-scroll-reveal").split(/[, ]+/),o={};return i=e(i),i.forEach(function(t,e){switch(t){case"enter":return void(o.enter=i[e+1]);case"after":return void(o.after=i[e+1]);case"wait":return void(o.after=i[e+1]);case"move":return void(o.move=i[e+1]);case"ease":return o.move=i[e+1],void(o.ease="ease");case"ease-in":return o.move=i[e+1],void(o.easing="ease-in");case"ease-in-out":return o.move=i[e+1],void(o.easing="ease-in-out");case"ease-out":return o.move=i[e+1],void(o.easing="ease-out");case"over":return void(o.over=i[e+1]);default:return}}),o},update:function(t){var e=this.genCSS(t),i=this.styleBank[t.getAttribute("data-scroll-reveal-id")];return null!=i?i+=";":i="",t.getAttribute("data-scroll-reveal-initialized")||(t.setAttribute("style",i+e.initial),t.setAttribute("data-scroll-reveal-initialized",!0)),this.isElementInViewport(t,this.options.viewportFactor)?t.getAttribute("data-scroll-reveal-complete")?void 0:this.isElementInViewport(t,this.options.viewportFactor)?(t.setAttribute("style",i+e.target+e.transition),void(this.options.reset||setTimeout(function(){""!=i?t.setAttribute("style",i):t.removeAttribute("style"),t.setAttribute("data-scroll-reveal-complete",!0)},e.totalDuration))):void 0:void(this.options.reset&&t.setAttribute("style",i+e.initial+e.reset))},genCSS:function(t){var e,i,o=this.parseLanguage(t);o.enter?(("top"==o.enter||"bottom"==o.enter)&&(e=o.enter,i="y"),("left"==o.enter||"right"==o.enter)&&(e=o.enter,i="x")):(("top"==this.options.enter||"bottom"==this.options.enter)&&(e=this.options.enter,i="y"),("left"==this.options.enter||"right"==this.options.enter)&&(e=this.options.enter,i="x")),("top"==e||"left"==e)&&(o.move=o.move?"-"+o.move:"-"+this.options.move);var r=o.move||this.options.move,n=o.over||this.options.over,s=o.after||this.options.after,a=o.easing||this.options.easing,l=o.opacity||this.options.opacity,u="-webkit-transition: -webkit-transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" "+s+", opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",c="-webkit-transition: -webkit-transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";transition: transform "+n+" "+a+" 0s, opacity "+n+" "+a+" "+s+";-webkit-perspective: 1000;-webkit-backface-visibility: hidden;",f="-webkit-transform: translate"+i+"("+r+");transform: translate"+i+"("+r+");opacity: "+l+";",p="-webkit-transform: translate"+i+"(0);transform: translate"+i+"(0);opacity: 1;";return{transition:u,initial:f,target:p,reset:c,totalDuration:1e3*(parseFloat(n)+parseFloat(s))}},getViewportH:function(){var e=this.docElem.clientHeight,i=t.innerHeight;return i>e?i:e},getOffset:function(t){var e=0,i=0;do isNaN(t.offsetTop)||(e+=t.offsetTop),isNaN(t.offsetLeft)||(i+=t.offsetLeft);while(t=t.offsetParent);return{top:e,left:i}},isElementInViewport:function(e,i){var o=t.pageYOffset,r=o+this.getViewportH(),n=e.offsetHeight,s=this.getOffset(e).top,a=s+n,i=i||0;return r>=s+n*i&&a>=o||"fixed"==(e.currentStyle?e.currentStyle:t.getComputedStyle(e,null)).position},extend:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}},e}(window),scrollReveal}); \ No newline at end of file diff --git a/scrollReveal.js b/scrollReveal.js index cf1fab76..fc81431a 100644 --- a/scrollReveal.js +++ b/scrollReveal.js @@ -4,7 +4,7 @@ ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ - |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.2 + |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.3 _/ | |__/ @@ -27,7 +27,7 @@ window.scrollReveal = (function (window) { 'use strict'; - + // generator (increments) for the next scroll-reveal-id var nextId = 1;