Skip to content
Browse files

Added more code comments.

Added example of horizontal version.
Added minified version of plugin.
  • Loading branch information...
1 parent 4236ba8 commit 484ba0b302da8174f81f50a1abefaeadda4662c4 Dave Cranwell committed May 26, 2011
Showing with 122 additions and 51 deletions.
  1. +43 −0 index-horizontal.html
  2. +1 −1 index.html
  3. +2 −2 jquery.scrollParallax.js
  4. +15 −0 jquery.scrollParallax.min.js
  5. +8 −6 scripts.js
  6. +53 −42 styles.css
View
43 index-horizontal.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
+<head>
+<meta charset="utf-8" />
+
+<link rel="stylesheet" href="reset.css" />
+<link rel="stylesheet" href="styles.css" />
+
+</head>
+<body>
+
+<ul class="items-horizontal">
+ <li class="item item1">
+ <div class="inner inner1"></div>
+ <div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam hendrerit, risus in venenatis tempor, magna diam ultrices justo, in sodales odio tellus vel quam. Nam eros felis, vulputate a porta ac, rutrum in magna. Donec at tellus velit. Duis non nisi pellentesque mauris vehicula adipiscing. Sed sodales consectetur quam in faucibus. Curabitur a turpis in elit elementum vehicula. Proin fermentum bibendum rutrum. Nullam non sagittis nulla. Nulla nisi mi, placerat ac rhoncus pharetra, pharetra at enim. Vestibulum consectetur sem nec orci volutpat dictum eu condimentum eros. Fusce venenatis malesuada metus, non molestie velit sagittis et. Nullam tellus sapien, imperdiet sit amet posuere vel, sagittis nec turpis. In eget neque erat, euismod lobortis nibh. Maecenas lorem sapien, fermentum in pharetra eget, aliquam ac leo. Maecenas adipiscing porttitor turpis, a pretium justo faucibus eget. Nullam eu purus enim. Cras non felis at turpis auctor bibendum sit amet nec tellus. Fusce interdum sem et purus fermentum faucibus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque euismod commodo tellus, at gravida risus imperdiet quis.</div>
+ </li>
+ <li class="item item2">
+ <div class="inner inner2"></div>
+ <div class="inner-lev1 inner2a"></div>
+ <div class="inner-lev2 inner2b"></div>
+ <div class="content">Vivamus tristique, dolor nec vehicula tincidunt, sem risus convallis arcu, sed porttitor magna augue vel nisl. Phasellus ut enim ac neque egestas rhoncus. Praesent diam quam, sodales at ultricies non, pellentesque non quam. Vestibulum tristique dictum facilisis. In id justo orci, a pretium odio. Aliquam elit neque, aliquam vitae vestibulum a, interdum in urna. Nunc nec risus vitae tortor rhoncus molestie. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent lacus purus, imperdiet id rhoncus eget, tincidunt eu velit. Nam mattis, mauris eu tempus sodales, nisl neque ultricies eros, sit amet fermentum urna risus sit amet nunc.</div>
+ </li>
+ <li class="item item3">
+ <div class="inner inner3"></div>
+ <div class="content">Morbi venenatis malesuada nibh vel sodales. Ut quis porttitor eros. Nam cursus adipiscing ligula, et fermentum nisl laoreet ut. Sed rhoncus ultrices elementum. Duis tincidunt massa id dui sollicitudin fermentum mollis felis ullamcorper. Ut ligula nisl, interdum ac cursus ac, hendrerit nec odio. Nunc eget tellus quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce et eleifend purus. Cras elementum tristique tortor. Integer nec tortor enim, ac tempus mi. Nulla rhoncus accumsan massa, eu auctor mi accumsan quis. Pellentesque eget lacus non urna bibendum varius in sit amet lectus. Ut ac sapien risus, id porttitor odio. Vestibulum porttitor, est non consequat placerat, ipsum est sagittis nisi, iaculis ultrices nisi lacus quis nisi. Quisque a rhoncus nisl. Praesent luctus velit eu leo faucibus vehicula.</div>
+ </li>
+ <li class="item item4">
+ <div class="inner inner4"></div>
+ <div class="content">Sed dapibus, quam a consequat ultricies, dui sem ultricies odio, id aliquet diam tortor at sapien. Nam eget magna a magna pharetra venenatis. Pellentesque eu nunc felis, sit amet hendrerit ipsum. Vestibulum massa nisl, consequat vitae tempor et, lobortis id enim. Fusce mattis faucibus rhoncus. Pellentesque neque turpis, ultricies ut congue et, laoreet ut odio. Sed sed erat sed nibh euismod pellentesque. Proin varius arcu ut felis pellentesque molestie. Aenean bibendum euismod sodales. Morbi sollicitudin odio vel turpis tristique at hendrerit magna venenatis. Donec non est ac dui placerat aliquet.</div>
+ </li>
+ <li class="item item5">
+ <div class="inner inner5"></div>
+ <div class="content">Ut dui erat, condimentum non vestibulum eget, blandit nec dui. Nam eu leo eget dui porta dapibus eu vitae tellus. Vivamus suscipit risus at libero tincidunt a facilisis orci vulputate. In venenatis ullamcorper nisi, eu cursus lectus porttitor aliquet. Suspendisse condimentum nunc et orci pharetra ut tempor odio faucibus. Integer porta semper ipsum, a porta libero lobortis in. Donec vestibulum ornare velit vehicula bibendum. Nam eget commodo nisl. Suspendisse ullamcorper est et orci accumsan eleifend. Integer vel nulla a velit scelerisque aliquam. Mauris et dolor posuere nulla placerat euismod. Sed consequat, orci et congue vehicula, elit velit viverra tellus, sed feugiat lorem sem non diam. Mauris ligula massa, porttitor nec tincidunt non, rhoncus eget lorem. Cras sit amet urna magna. Fusce erat dolor, blandit eu pulvinar at, feugiat et lacus. Proin semper adipiscing velit sit amet dapibus. Aliquam nec pulvinar erat. Nulla eget orci nec nunc molestie venenatis eu sed tortor. Cras dapibus cursus dui tincidunt viverra. Proin eget arcu ligula.</div>
+ </li>
+</ul>
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
+<script src="https://github.com/protonet/jquery.inview/raw/master/jquery.inview.min.js"></script>
+<script src="jquery.scrollParallax.min.js"></script>
+<script src="scripts.js"></script>
+
+</body>
+</html>
View
2 index.html
@@ -36,7 +36,7 @@
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="https://github.com/protonet/jquery.inview/raw/master/jquery.inview.min.js"></script>
-<script src="jquery.scrollParallax.js"></script>
+<script src="jquery.scrollParallax.min.js"></script>
<script src="scripts.js"></script>
</body>
View
4 jquery.scrollParallax.js
@@ -72,7 +72,7 @@
var settings = {
'speed': 0.2,
'axis': 'x,y',
- 'debug': false,
+ 'debug': false
}
function debug(msg){
@@ -113,7 +113,7 @@
//calculate new position
if(settings.axis.match(/x/)){
var Xpos = offset.left - $(window).scrollLeft();
- var newXPos = (-(Xpos) * settings.speed) + currentXPos
+ var newXPos = (-(Xpos) * settings.speed) + currentXPos;
}else{
var newXPos = currentXPos;
}
View
15 jquery.scrollParallax.min.js
@@ -0,0 +1,15 @@
+/*!
+ * Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
+ * backgroundPosition cssHook for jquery. Necessary to combat different css property names between browsers
+ * https://github.com/brandonaaron/jquery-cssHooks
+ * Licensed under the MIT License (LICENSE.txt).
+ */
+(function(c){var a=c('<div style="background-position: 3px 5px">');c.support.backgroundPosition=a.css("backgroundPosition")==="3px 5px"?true:false;c.support.backgroundPositionXY=a.css("backgroundPositionX")==="3px"?true:false;a=null;var d=["X","Y"];function b(g){var f=g.split(/\s/),e={X:f[0],Y:f[1]};return e}if(!c.support.backgroundPosition&&c.support.backgroundPositionXY){c.cssHooks.backgroundPosition={get:function(g,f,e){return c.map(d,function(h,j){return c.css(g,"backgroundPosition"+h)}).join(" ")},set:function(e,f){c.each(d,function(j,g){var h=b(f);e.style["backgroundPosition"+g]=h[g]})}}}if(c.support.backgroundPosition&&!c.support.backgroundPositionXY){c.each(d,function(f,e){c.cssHooks["backgroundPosition"+e]={get:function(j,i,g){var h=b(c.css(j,"backgroundPosition"));return h[e]},set:function(h,j){var g=b(c.css(h,"backgroundPosition")),i=e==="X";h.style.backgroundPosition=(i?j:g.X)+" "+(i?g.Y:j)}};c.fx.step["backgroundPosition"+e]=function(g){c.cssHooks["backgroundPosition"+e].set(g.elem,g.now+g.unit)}})}})(jQuery);
+/*!
+ * Scroll-based parallax plugin for jQuery
+ * Copyright (c) 2011 Dave Cranwell (http://davecranwell.com)
+ * Licensed under the MIT License.
+ * 2011-05-18
+ * version 1.0
+ */
+(function(a){a.fn.scrollParallax=function(c){var d={speed:0.2,axis:"x,y",debug:false};function b(e){if(d.debug&&"console" in window&&"log" in window.console){console.log(e)}}return this.each(function(){var h=a(this);if(c){a.extend(d,c)}h.bind("inview",function(i,j){if(j==true){h.addClass("inview");b("in view")}else{h.removeClass("inview");b("out of view")}});var f=h.css("backgroundPosition").split(" ");var g=parseInt(f[0].replace(/[^0-9\-]/g,""));var e=parseInt(f[1].replace(/[^0-9\-]/g,""));a(window).bind("scroll",function(){if(h.hasClass("inview")){var l=h.offset();if(d.axis.match(/x/)){var m=l.left-a(window).scrollLeft();var k=(-(m)*d.speed)+g}else{var k=g}if(d.axis.match(/y/)){var j=l.top-a(window).scrollTop();var i=(-(j)*d.speed)+e}else{var i=e}b("new X position: "+k);b("new Y position: "+i);h.css({backgroundPosition:parseInt(k)+"px "+parseInt(i)+"px"})}})})}})(jQuery);
View
14 scripts.js
@@ -1,17 +1,19 @@
$(function(){
- $('.items li').scrollParallax({
+ /* main background image. moves against the direction of scroll*/
+ $('.item').scrollParallax({
'speed': -0.2
});
- $('.items .inner').scrollParallax({
+ /* inner items, moves slightly faster than the background */
+ $('.item .inner').scrollParallax({
'speed': -0.5
});
- $('.items .inner-lev1').scrollParallax({
+ /* two additional samples inside item2, both moving with direction of scroll*/
+ $('.item .inner-lev1').scrollParallax({
'speed': 0.2
- });
-
- $('.items .inner-lev2').scrollParallax({
+ });
+ $('.item .inner-lev2').scrollParallax({
'speed': 0.5
});
});
View
95 styles.css
@@ -1,3 +1,4 @@
+/* vertical version */
.items{
overflow:hidden;
}
@@ -11,51 +12,61 @@
width:100%;
height:100%;
position:absolute;
+ z-index:1;
}
- .content{
- background:rgba(255,255,255,0.9);
- background:white;
- padding:20px;
- width:300px;
- margin:30px;
- }
-
- .item1{
- background: white url(http://lorempixum.com/1024/768/city/1) 0px 0px fixed no-repeat;
- }
- .inner1{
- background: url(http://lorempixum.com/200/200/people/1) 400px 200px fixed no-repeat;
+ .content{
+ background:rgba(255,255,255,0.9);
+ background:white;
+ padding:20px;
+ width:300px;
+ margin:30px;
+ position:relative;
+ z-index:2;
}
- .item2{
- background: white url(http://lorempixum.com/1024/768/city/2) 0px 0px fixed no-repeat;
+
+/* alterations for horizontal version */
+.items-horizontal{
+ width:5120px;
+}
+ .items-horizontal .item{
+ width:1024px;
+ float:left;
}
- .inner2{
- background: url(http://lorempixum.com/200/200/people/2) 400px 200px fixed no-repeat;
- }
- .inner2a{
- background: url(http://lorempixum.com/200/200/sports/1) 500px 250px fixed no-repeat;
- }
- .inner2b{
- background: url(http://lorempixum.com/200/200/sports/2) 600px 300px fixed no-repeat;
- }
- .item3{
- background: white url(http://lorempixum.com/1024/768/city/3) 0px 0px fixed no-repeat;
+
+/* parallax images */
+.item1{
+ background: white url(http://lorempixum.com/1024/768/city/1) 0px 0px fixed no-repeat;
+}
+ .inner1{
+ background: url(http://lorempixum.com/200/200/people/1) 400px 200px fixed no-repeat;
}
- .inner3{
- background: url(http://lorempixum.com/200/200/people/3) 400px 200px fixed no-repeat;
- }
- .item4{
- background: white url(http://lorempixum.com/1024/768/city/4) 0px 0px fixed no-repeat;
+.item2{
+ background: white url(http://lorempixum.com/1024/768/city/2) 0px 0px fixed no-repeat;
+}
+ .inner2{
+ background: url(http://lorempixum.com/200/200/people/2) 400px 200px fixed no-repeat;
}
- .inner4{
- background: url(http://lorempixum.com/200/200/people/4) 400px 200px fixed no-repeat;
- }
- .item5{
- background: white url(http://lorempixum.com/1024/768/city/5) 0px 0px fixed no-repeat;
+ .inner2a{
+ background: url(http://lorempixum.com/200/200/sports/1) 500px 250px fixed no-repeat;
}
- .inner5{
- background: url(http://lorempixum.com/200/200/people/5) 400px 200px fixed no-repeat;
- }
-
-
-
+ .inner2b{
+ background: url(http://lorempixum.com/200/200/sports/2) 600px 300px fixed no-repeat;
+ }
+.item3{
+ background: white url(http://lorempixum.com/1024/768/city/3) 0px 0px fixed no-repeat;
+}
+ .inner3{
+ background: url(http://lorempixum.com/200/200/people/3) 400px 200px fixed no-repeat;
+ }
+.item4{
+ background: white url(http://lorempixum.com/1024/768/city/4) 0px 0px fixed no-repeat;
+}
+ .inner4{
+ background: url(http://lorempixum.com/200/200/people/4) 400px 200px fixed no-repeat;
+ }
+.item5{
+ background: white url(http://lorempixum.com/1024/768/city/5) 0px 0px fixed no-repeat;
+}
+ .inner5{
+ background: url(http://lorempixum.com/200/200/people/5) 400px 200px fixed no-repeat;
+ }

0 comments on commit 484ba0b

Please sign in to comment.
Something went wrong with that request. Please try again.