From 50a3c4bf0f1671ff47ef60209bf124d26a11db8a Mon Sep 17 00:00:00 2001 From: Sebastian Troc Date: Mon, 23 Jul 2012 10:27:24 +0200 Subject: [PATCH 1/4] Add parallax efect for DOM elements Add parallax efect for DOM elements top position not only for their background-image properties --- scripts/jquery.parallax-1.1.3.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/jquery.parallax-1.1.3.js b/scripts/jquery.parallax-1.1.3.js index f3569dc..9c87b31 100644 --- a/scripts/jquery.parallax-1.1.3.js +++ b/scripts/jquery.parallax-1.1.3.js @@ -19,8 +19,8 @@ http://www.gnu.org/licenses/gpl.html windowHeight = $window.height(); }); - $.fn.parallax = function(xpos, speedFactor, outerHeight) { - var $this = $(this); + $.fn.parallax = function(xpos, speedFactor, outerHeight, staticImage) { + var $this = $(this); var getHeight; var firstTop; var paddingTop = 0; @@ -44,6 +44,7 @@ http://www.gnu.org/licenses/gpl.html if (arguments.length < 1 || xpos === null) xpos = "50%"; if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1; if (arguments.length < 3 || outerHeight === null) outerHeight = true; + if (arguments.length < 4 || staticImage === null) staticImage = false; // function to be called whenever the window is scrolled or resized function update(){ @@ -59,7 +60,12 @@ http://www.gnu.org/licenses/gpl.html return; } - $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); + if (staticImage == true) { + $this.css('top', Math.round((firstTop - pos) * speedFactor) - 100 + "px"); + } else { + $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); + } + }); } From ebb597938e924d6a5ded31ff94c9baf246aa7860 Mon Sep 17 00:00:00 2001 From: Sebastian Troc Date: Mon, 23 Jul 2012 10:41:20 +0200 Subject: [PATCH 2/4] Fix default value for third farameter In my experiments I initialized the plugin with third parameter as empty string (''). So I handled this exception. --- scripts/jquery.parallax-1.1.3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/jquery.parallax-1.1.3.js b/scripts/jquery.parallax-1.1.3.js index 9c87b31..b573d2b 100644 --- a/scripts/jquery.parallax-1.1.3.js +++ b/scripts/jquery.parallax-1.1.3.js @@ -43,7 +43,7 @@ http://www.gnu.org/licenses/gpl.html // setup defaults if arguments aren't specified if (arguments.length < 1 || xpos === null) xpos = "50%"; if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1; - if (arguments.length < 3 || outerHeight === null) outerHeight = true; + if (arguments.length < 3 || outerHeight === null || typeof outerHeight === 'string') outerHeight = true; if (arguments.length < 4 || staticImage === null) staticImage = false; // function to be called whenever the window is scrolled or resized From 5b0366b3185cf8768d602b9ebeed1ca6c1783c01 Mon Sep 17 00:00:00 2001 From: Sebastian Troc Date: Mon, 23 Jul 2012 11:18:47 +0200 Subject: [PATCH 3/4] Samples in demo Sample of parallax for elements top positions --- index.html | 164 +++++++++++++++++--------------- style.css | 272 +++++++++++++++++++++++++++-------------------------- 2 files changed, 226 insertions(+), 210 deletions(-) diff --git a/index.html b/index.html index 0a07d59..6d2d6a1 100755 --- a/index.html +++ b/index.html @@ -1,70 +1,80 @@ - + - - -jQuery Parallax Plugin Demo - - - - - - + + + + - - - - - -
-
-
-

(Almost) Static Background

-

This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.

-
-
-
- -
-
-
-

Multiple Backgrounds

-

The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.

-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nibh erat, sagittis sit amet congue at, aliquam eu libero. Integer molestie, turpis vel ultrices facilisis, nisi mauris sollicitudin mauris, volutpat elementum enim urna eget odio. Donec egestas aliquet facilisis. Nunc eu nunc eget neque ornare fringilla. Nam vel sodales lectus. Nulla in pellentesque eros. Donec ultricies, enim vitae varius cursus, risus mauris iaculis neque, euismod sollicitudin metus erat vitae sapien. Sed pulvinar.

-
-
- -
- -
-
-
-

What Happens When JavaScript is Disabled?

-

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

-
-
-
- -
+ $('.bg').parallax("50%", 0.4); + $('#third').parallax("50%", 0.3); + $('.firstElem').parallax("50%", 0.5, '', true); + $('.secondElem').parallax("50%", 0.9, '', true); + $('.thirdElem').parallax("50%", 1.1, '', true); +}) + + + + + + +
-

Check out my new plugin Sequence.js for parallax effects and a whole lot more!

+
+

(Almost) Static Background

+

This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.

+
+
+
+ +
+
+
+

Multiple Backgrounds

+

The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nibh erat, sagittis sit amet congue at, aliquam eu libero. Integer molestie, turpis vel ultrices facilisis, nisi mauris sollicitudin mauris, volutpat elementum enim urna eget odio. Donec egestas aliquet facilisis. Nunc eu nunc eget neque ornare fringilla. Nam vel sodales lectus. Nulla in pellentesque eros. Donec ultricies, enim vitae varius cursus, risus mauris iaculis neque, euismod sollicitudin metus erat vitae sapien. Sed pulvinar.

+
+
+ +
+ +
+
+
+

What Happens When JavaScript is Disabled?

+

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

+
+
+

What Happens When JavaScript is Disabled?

+

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

+
+
+

What Happens When JavaScript is Disabled?

+

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

+
+
+
+ +
+
+

Check out my new plugin Sequence.js for parallax effects and a whole lot more!

Ian Lunn

    @@ -74,17 +84,17 @@

    Ian Lunn

This demo is based on the Nikebetterworld.com website.

- -

Credits

-

This plugin makes use of some scripts and images made by others:

- -
-
- - + +

Credits

+

This plugin makes use of some scripts and images made by others:

+ +
+ + + diff --git a/style.css b/style.css index 3c5d8dd..8fcd064 100755 --- a/style.css +++ b/style.css @@ -1,136 +1,142 @@ -/* -Plugin: jQuery Parallax -Version 1.1.3 +/* +Plugin: jQuery Parallax +Version 1.1.3 Author: Ian Lunn -Twitter: @IanLunn -Author URL: http://www.ianlunn.co.uk/ -Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ - -License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to http://www.ianlunn.co.uk/. -*/ - -@charset "utf-8"; -/* CSS Document */ - -body{ - margin: 0; - min-width: 980px; +Twitter: @IanLunn +Author URL: http://www.ianlunn.co.uk/ +Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ + +License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to http://www.ianlunn.co.uk/. +*/ + +@charset "utf-8"; +/* CSS Document */ + +body{ + margin: 0; + min-width: 980px; padding: 0; -} - -p{ - margin: 0 0 20px 0; -} - -p, ul{ - font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif; - font-size-adjust:0.488; - font-weight:200; - font-style:normal; -} - -img{ - border: 0; -} - -h1, #pixels{ - font-family:"Museo 900", Verdana, serif; - font-size-adjust:0.40; - font-weight:700; - font-style:normal; -} - -h2{ - font-family:"Beau Sans Pro Book", Verdana, sans-serif; - font-size-adjust:0.531; - font-weight:500; - font-style:normal; -} - -#header h1, #pixels{ - color: #48941A; -} - -.float-left{ - float: left; - margin: 0 0 0 20px; -} - -.float-right{ - float: right; - margin: 0 20px 0 0; -} - -.center{ - font-size: 2.5em; - padding: 80px 0 0 0; - text-align: center; -} - -#nav{ - list-style: none; - position: fixed; - right: 20px; -} - -#nav li{ - margin: 0 0 15px 0; -} - -#header, #intro, #second{ - width: 100%; -} - -#intro{ - background:url(images/firstBG.jpg) 50% 0 no-repeat fixed; - color: white; - height: 600px; - margin: 0 auto; - padding: 0; -} - -#second{ - background: url(images/secondBG.jpg) 50% 0 no-repeat fixed; - color: white; - height: 1300px; - margin: 0 auto; - overflow: hidden; - padding: 0; -} - -#second .bg{ - background: url(images/trainers.png) 50% 0 no-repeat fixed; - height: 1300px; - margin: 0 auto; - padding: 0; - position: absolute; - width: 900px; - z-index: 200; -} - -#third{ - background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed; - color: white; - height: 650px; - padding: 100px 0 0 0; -} - -#fifth{ - background: #ccc; - height: 400px; - margin: 0 auto; - padding: 40px 0 0 0; -} - -.story{ - margin: 0 auto; - min-width: 980px; - overflow: auto; - width: 980px; -} - -.story .float-left, .story .float-right{ - padding: 100px 0 0 0; - position: relative; - width: 350px; } + +p{ + margin: 0 0 20px 0; +} + +p, ul{ + font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif; + font-size-adjust:0.488; + font-weight:200; + font-style:normal; +} + +img{ + border: 0; +} + +h1, #pixels{ + font-family:"Museo 900", Verdana, serif; + font-size-adjust:0.40; + font-weight:700; + font-style:normal; +} + +h2{ + font-family:"Beau Sans Pro Book", Verdana, sans-serif; + font-size-adjust:0.531; + font-weight:500; + font-style:normal; +} + +#header h1, #pixels{ + color: #48941A; +} + +.float-left{ + float: left; + margin: 0 0 0 20px; +} + +.float-right{ + float: right; + margin: 0 20px 0 0; +} + +.center{ + font-size: 2.5em; + padding: 80px 0 0 0; + text-align: center; +} + +#nav{ + list-style: none; + position: fixed; + right: 20px; +} + +#nav li{ + margin: 0 0 15px 0; +} + +#header, #intro, #second{ + width: 100%; +} + +#intro{ + background:url(images/firstBG.jpg) 50% 0 no-repeat fixed; + color: white; + height: 600px; + margin: 0 auto; + padding: 0; +} + +#second{ + background: url(images/secondBG.jpg) 50% 0 no-repeat fixed; + color: white; + height: 1300px; + margin: 0 auto; + overflow: hidden; + padding: 0; +} + +#second .bg{ + background: url(images/trainers.png) 50% 0 no-repeat fixed; + height: 1300px; + margin: 0 auto; + padding: 0; + position: absolute; + width: 900px; + z-index: 200; +} + +#third{ + background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed; + color: white; + height: 650px; + padding: 100px 0 0 0; +} + +#fifth{ + background: #ccc; + height: 400px; + margin: 0 auto; + padding: 40px 0 0 0; +} + +.story{ + margin: 0 auto; + min-width: 980px; + overflow: auto; + width: 980px; +} +#third .story { + height: 700px; +} + +.story .float-left, .story .float-right{ + padding: 100px 0 0 0; + position: relative; + width: 300px; +} +.firstElem, .secondElem, .thirdElem{ + position: relative; +} \ No newline at end of file From 339e6d6bd09b88696dec4f9cac6456237df573ee Mon Sep 17 00:00:00 2001 From: Sebastian Troc Date: Mon, 23 Jul 2012 11:20:59 +0200 Subject: [PATCH 4/4] Revert "Samples in demo" This reverts commit 5b0366b3185cf8768d602b9ebeed1ca6c1783c01. --- index.html | 164 +++++++++++++++----------------- style.css | 272 ++++++++++++++++++++++++++--------------------------- 2 files changed, 210 insertions(+), 226 deletions(-) diff --git a/index.html b/index.html index 6d2d6a1..0a07d59 100755 --- a/index.html +++ b/index.html @@ -1,80 +1,70 @@ - + - - -jQuery Parallax Plugin Demo - - - - - - + + + + - - - - - -
+ $('.bg').parallax("50%", 0.4); + $('#third').parallax("50%", 0.3); + +}) + + + + + + +
+
+
+

(Almost) Static Background

+

This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.

+
+
+
+ +
+
+
+

Multiple Backgrounds

+

The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nibh erat, sagittis sit amet congue at, aliquam eu libero. Integer molestie, turpis vel ultrices facilisis, nisi mauris sollicitudin mauris, volutpat elementum enim urna eget odio. Donec egestas aliquet facilisis. Nunc eu nunc eget neque ornare fringilla. Nam vel sodales lectus. Nulla in pellentesque eros. Donec ultricies, enim vitae varius cursus, risus mauris iaculis neque, euismod sollicitudin metus erat vitae sapien. Sed pulvinar.

+
+
+ +
+ +
+
+
+

What Happens When JavaScript is Disabled?

+

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

+
+
+
+ +
-
-

(Almost) Static Background

-

This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.

-
-
-
- -
-
-
-

Multiple Backgrounds

-

The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.

-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nibh erat, sagittis sit amet congue at, aliquam eu libero. Integer molestie, turpis vel ultrices facilisis, nisi mauris sollicitudin mauris, volutpat elementum enim urna eget odio. Donec egestas aliquet facilisis. Nunc eu nunc eget neque ornare fringilla. Nam vel sodales lectus. Nulla in pellentesque eros. Donec ultricies, enim vitae varius cursus, risus mauris iaculis neque, euismod sollicitudin metus erat vitae sapien. Sed pulvinar.

-
-
- -
- -
-
-
-

What Happens When JavaScript is Disabled?

-

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

-
-
-

What Happens When JavaScript is Disabled?

-

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

-
-
-

What Happens When JavaScript is Disabled?

-

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

-
-
-
- -
-
-

Check out my new plugin Sequence.js for parallax effects and a whole lot more!

+

Check out my new plugin Sequence.js for parallax effects and a whole lot more!

Ian Lunn

    @@ -84,17 +74,17 @@

    Ian Lunn

This demo is based on the Nikebetterworld.com website.

- -

Credits

-

This plugin makes use of some scripts and images made by others:

- -
-
- - + +

Credits

+

This plugin makes use of some scripts and images made by others:

+ +
+ + + diff --git a/style.css b/style.css index 8fcd064..3c5d8dd 100755 --- a/style.css +++ b/style.css @@ -1,142 +1,136 @@ -/* -Plugin: jQuery Parallax -Version 1.1.3 +/* +Plugin: jQuery Parallax +Version 1.1.3 Author: Ian Lunn -Twitter: @IanLunn -Author URL: http://www.ianlunn.co.uk/ -Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ - -License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to http://www.ianlunn.co.uk/. -*/ - -@charset "utf-8"; -/* CSS Document */ - -body{ - margin: 0; - min-width: 980px; +Twitter: @IanLunn +Author URL: http://www.ianlunn.co.uk/ +Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ + +License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to http://www.ianlunn.co.uk/. +*/ + +@charset "utf-8"; +/* CSS Document */ + +body{ + margin: 0; + min-width: 980px; padding: 0; +} + +p{ + margin: 0 0 20px 0; +} + +p, ul{ + font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif; + font-size-adjust:0.488; + font-weight:200; + font-style:normal; +} + +img{ + border: 0; +} + +h1, #pixels{ + font-family:"Museo 900", Verdana, serif; + font-size-adjust:0.40; + font-weight:700; + font-style:normal; +} + +h2{ + font-family:"Beau Sans Pro Book", Verdana, sans-serif; + font-size-adjust:0.531; + font-weight:500; + font-style:normal; +} + +#header h1, #pixels{ + color: #48941A; +} + +.float-left{ + float: left; + margin: 0 0 0 20px; +} + +.float-right{ + float: right; + margin: 0 20px 0 0; +} + +.center{ + font-size: 2.5em; + padding: 80px 0 0 0; + text-align: center; +} + +#nav{ + list-style: none; + position: fixed; + right: 20px; +} + +#nav li{ + margin: 0 0 15px 0; +} + +#header, #intro, #second{ + width: 100%; +} + +#intro{ + background:url(images/firstBG.jpg) 50% 0 no-repeat fixed; + color: white; + height: 600px; + margin: 0 auto; + padding: 0; +} + +#second{ + background: url(images/secondBG.jpg) 50% 0 no-repeat fixed; + color: white; + height: 1300px; + margin: 0 auto; + overflow: hidden; + padding: 0; +} + +#second .bg{ + background: url(images/trainers.png) 50% 0 no-repeat fixed; + height: 1300px; + margin: 0 auto; + padding: 0; + position: absolute; + width: 900px; + z-index: 200; +} + +#third{ + background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed; + color: white; + height: 650px; + padding: 100px 0 0 0; +} + +#fifth{ + background: #ccc; + height: 400px; + margin: 0 auto; + padding: 40px 0 0 0; +} + +.story{ + margin: 0 auto; + min-width: 980px; + overflow: auto; + width: 980px; +} + +.story .float-left, .story .float-right{ + padding: 100px 0 0 0; + position: relative; + width: 350px; } - -p{ - margin: 0 0 20px 0; -} - -p, ul{ - font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif; - font-size-adjust:0.488; - font-weight:200; - font-style:normal; -} - -img{ - border: 0; -} - -h1, #pixels{ - font-family:"Museo 900", Verdana, serif; - font-size-adjust:0.40; - font-weight:700; - font-style:normal; -} - -h2{ - font-family:"Beau Sans Pro Book", Verdana, sans-serif; - font-size-adjust:0.531; - font-weight:500; - font-style:normal; -} - -#header h1, #pixels{ - color: #48941A; -} - -.float-left{ - float: left; - margin: 0 0 0 20px; -} - -.float-right{ - float: right; - margin: 0 20px 0 0; -} - -.center{ - font-size: 2.5em; - padding: 80px 0 0 0; - text-align: center; -} - -#nav{ - list-style: none; - position: fixed; - right: 20px; -} - -#nav li{ - margin: 0 0 15px 0; -} - -#header, #intro, #second{ - width: 100%; -} - -#intro{ - background:url(images/firstBG.jpg) 50% 0 no-repeat fixed; - color: white; - height: 600px; - margin: 0 auto; - padding: 0; -} - -#second{ - background: url(images/secondBG.jpg) 50% 0 no-repeat fixed; - color: white; - height: 1300px; - margin: 0 auto; - overflow: hidden; - padding: 0; -} - -#second .bg{ - background: url(images/trainers.png) 50% 0 no-repeat fixed; - height: 1300px; - margin: 0 auto; - padding: 0; - position: absolute; - width: 900px; - z-index: 200; -} - -#third{ - background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed; - color: white; - height: 650px; - padding: 100px 0 0 0; -} - -#fifth{ - background: #ccc; - height: 400px; - margin: 0 auto; - padding: 40px 0 0 0; -} - -.story{ - margin: 0 auto; - min-width: 980px; - overflow: auto; - width: 980px; -} -#third .story { - height: 700px; -} - -.story .float-left, .story .float-right{ - padding: 100px 0 0 0; - position: relative; - width: 300px; -} -.firstElem, .secondElem, .thirdElem{ - position: relative; -} \ No newline at end of file