Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed naming convention conflicts. Created horizontal scrolling feature.

  • Loading branch information...
commit 9f7d3962db7687e0c26bf3e5da53e6aca5845aa2 1 parent ae186c8
CodeHunger authored
View
53 source/controllers/scroll.js
@@ -1,19 +1,22 @@
////////////////////////////////////////////////////////////////////////////////
// Scroll controller ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-ControllerScroll = function(smoothing, scrollSpace) {
+ControllerScroll = function(smoothing, horizontal, convertScroll) {
this.target = $(window);
+ this.horizontal = horizontal;
+ this.convertScroll = convertScroll;
$(window).scrollTop(0);
- this.height = parseInt($("body").css('height'),10);
- this.scrollSpace = scrollSpace || this.height - this.target.height();
-
- if (this.scrollSpace < 10) {
- this.height = parseInt($("#wrapper").css('height'),10);
- this.scrollSpace = this.height - this.target.height();
+ $(window).scrollLeft(0);
+
+ if (!horizontal) {
+ var height = parseInt($("body").css('height'),10);
+ this.scrollSpace = height - this.target.height();
+ } else {
+ var width = parseInt($("body").css('width'),10);
+ this.scrollSpace = width - this.target.width();
}
-
+
this.smoothing = smoothing || false;
-
this.targetProgress = 0;
};
@@ -21,31 +24,44 @@ ControllerScroll.prototype = new JarallaxController();
ControllerScroll.prototype.activate = function(jarallax) {
JarallaxController.prototype.activate.call(this, jarallax);
+ if (this.convertScroll) {
+ scrollConverter.activate();
+ }
this.target.bind('scroll', {scope: this} , this.onScroll);
};
ControllerScroll.prototype.deactivate = function(jarallax) {
JarallaxController.prototype.deactivate.call(this, jarallax);
+ if (this.convertScroll) {
+ scrollConverter.deactivate();
+ }
this.target.unbind('scroll');
};
ControllerScroll.prototype.onScroll = function(event) {
var controller = event.data.scope;
-
+ //console.log(controller.target.scrollTop());
+
if(controller.jarallax.jumping){
- if(!controller.jarallax.jumping_allowed) {
+ if(!controller.jarallax.jumpingAllowed) {
controller.jarallax.clearSmooth(controller.jarallax);
}
}
if (controller.isActive) {
- var y = event.data.y || controller.target.scrollTop();
- var progress = y/controller.scrollSpace;
-
+ var progress;
+ if (!controller.horizontal) {
+ var y = event.data.y || controller.target.scrollTop();
+ progress = y/controller.scrollSpace;
+ } else {
+ var x = event.data.x || controller.target.scrollLeft();
+ progress = x/controller.scrollSpace;
+ }
+
if(!controller.smoothing){
controller.jarallax.setProgress(progress, true);
} else {
- controller.targetProgress = progress;
+ controller.targetProgress = Math.min(progress, 1);
controller.smooth();
}
}
@@ -60,7 +76,6 @@ ControllerScroll.prototype.smooth = function(externalScope) {
}
var oldProgress = scope.jarallax.progress;
-
var animationSpace = scope.targetProgress - oldProgress;
clearTimeout(scope.timer);
@@ -79,6 +94,10 @@ ControllerScroll.prototype.update = function(progress) {
var scrollPosition = progress * this.scrollSpace;
if(!this.jarallax.allowWeakProgress) {
- $(window).scrollTop(scrollPosition);
+ if (!controller.horizontal) {
+ $(window).scrollTop(scrollPosition);
+ } else {
+ $(window).scrollLeft(scrollPosition);
+ }
}
};
View
52 source/jarallax.js
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////////////////////////
// jarallax class //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-var Jarallax = function (controller) {
+var Jarallax = function () {
this.FPS = 24;
this.FPS_INTERVAL = 1000 / this.FPS;
this.FRAME_DATA_SAMPLE = 24;
@@ -11,7 +11,8 @@ var Jarallax = function (controller) {
this.animations = [];
this.defaultValues = [];
this.progress = 0.0;
- this.prev_progress = 0.0;
+ this.properties = {};
+ this.prevProgress = 0.0;
this.controllers = [];
this.maxProgress = 1;
this.timer = undefined;
@@ -19,24 +20,28 @@ var Jarallax = function (controller) {
this.frameRate = this.FPS;
this.stepSize = 0;
this.jumping = false;
-
- if (controller === undefined) {
- if($.browser.iDevice){
- this.controllers.push(new ControllerApple(false));
- } else if ($.browser.mozilla) {
- this.controllers.push(new ControllerScroll(false));
+
+ for(var argument in arguments) {
+ if (arguments[argument] instanceof Array){
+ this.controllers = arguments[argument];
+ } else if (arguments[argument].isController) {
+ this.controllers.push(arguments[argument]);
+ } else if (arguments[argument] instanceof Object) {
+ this.properties = arguments[argument];
} else {
- this.controllers.push(new ControllerScroll(true));
+ console.log('WARNING: bad argument ' + argument);
}
- } else if (controller !== 'none') {
- if (controller.length) {
- this.controllers = controller;
- } else if (typeof (controller) === 'object') {
- this.controllers.push(controller);
+ }
+
+ if (!this.controller) {
+ if($.browser.iDevice) {
+ this.controllers.push(new ControllerApple(false));
+ } else if ($.browser.mozilla) {
+ this.controllers.push(new ControllerScroll(false,
+ this.properties.horizontal, this.properties.disableVertical));
} else {
- throw new Error('wrong controller data type: "' +
- typeof (controller) +
- '". Expected "object" or "array"');
+ this.controllers.push(new ControllerScroll(true,
+ this.properties.horizontal, this.properties.disableVertical));
}
}
@@ -58,13 +63,14 @@ Jarallax.prototype.setProgress = function (progress, isWeak) {
progress = 1;
} else if (progress < 0) {
progress = 0;
- }else{
- progress = Math.round(progress * 1000) / 1000;
}
+
+ console.log(progress);
if(this.progress != progress){
this.progress = progress;
if (this.allowWeakProgress || !weak) {
+
this.previousTime = new Date();
this.currentTime = new Date();
var weak = isWeak || false;
@@ -148,16 +154,16 @@ Jarallax.prototype.smooth = function (externalScope) {
1,
5);
- scope.jumping_allowed = true;
+ scope.jumpingAllowed = true;
scope.setProgress(newProgress);
- scope.jumping_allowed = false;
+ scope.jumpingAllowed = false;
scope.timer = window.setTimeout(function(){scope.smooth(scope);}, scope.smoothProperties.timeStep);
scope.smoothProperties.previousValue = newProgress;
scope.allowWeakProgress = false;
} else {
- scope.jumping_allowed = true;
+ scope.jumpingAllowed = true;
scope.setProgress(scope.smoothProperties.startProgress + scope.smoothProperties.diffProgress);
- scope.jumping_allowed = false;
+ scope.jumpingAllowed = false;
scope.clearSmooth(scope);
}
};
View
50 source/jarallax_animation.js
@@ -71,48 +71,48 @@ JarallaxAnimation.prototype.activate = function (progress) {
}
};
-JarallaxAnimation.prototype.dispatchEvent = function(progress_old, progress_new,
+JarallaxAnimation.prototype.dispatchEvent = function(progressOld, progressNew,
start, end) {
var events = this.startValues.event;
- var event_data = {};
- event_data.animation = this;
- event_data.selector = this.selector;
+ var eventData = {};
+ eventData.animation = this;
+ eventData.selector = this.selector;
- if (progress_new >= start && progress_new <= end ) {
- if (events.start && progress_old < start) {
- event_data.type = 'start';
- events.start(event_data);
+ if (progressNew >= start && progressNew <= end ) {
+ if (events.start && progressOld < start) {
+ eventData.type = 'start';
+ events.start(eventData);
}
- if (events.start && progress_old > end) {
- event_data.type = 'rewind';
- events.start(event_data);
+ if (events.start && progressOld > end) {
+ eventData.type = 'rewind';
+ events.start(eventData);
}
if (events.animating) {
- event_data.type = 'animating';
- events.animating(event_data);
+ eventData.type = 'animating';
+ events.animating(eventData);
}
- if (events.forward && progress_old < progress_new) {
- event_data.type = 'forward';
- events.forward(event_data);
+ if (events.forward && progressOld < progressNew) {
+ eventData.type = 'forward';
+ events.forward(eventData);
}
- if (events.reverse && progress_old > progress_new) {
- event_data.type = 'reverse';
- events.reverse(event_data);
+ if (events.reverse && progressOld > progressNew) {
+ eventData.type = 'reverse';
+ events.reverse(eventData);
}
} else {
- if (events.complete && progress_old < end && progress_new > end) {
- event_data.type = 'complete';
- events.complete(event_data);
+ if (events.complete && progressOld < end && progressNew > end) {
+ eventData.type = 'complete';
+ events.complete(eventData);
}
- if (events.rewinded && progress_old > start && progress_new < start) {
- event_data.type = 'rewind';
- events.rewinded(event_data);
+ if (events.rewinded && progressOld > start && progressNew < start) {
+ eventData.type = 'rewind';
+ events.rewinded(eventData);
}
}
};
View
1  source/jarallax_controller.js
@@ -4,6 +4,7 @@
JarallaxController = function() {
this.isActive = false;
this.bindings = [];
+ this.isController = true;
};
View
10 source/jarallax_tools.js
@@ -116,16 +116,6 @@ JarallaxTools.Platforms = ['webkit',
'mobile',
'nonMobile'];
-/*jQuery.browser.webkit
-jQuery.browser.opera
-jQuery.browser.msie
-jQuery.browser.mozilla*/
-
-/**
- * jQuery.browser.mobile (http://detectmobilebrowser.com/)
- * jQuery.browser.mobile will be true if the browser is a mobile device
- **/
-//(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4));})(navigator.userAgent||navigator.vendor||window.opera);
jQuery.browser.android = /android/i.test(navigator.userAgent.toLowerCase());
jQuery.browser.blackBerry = /blackberry/i.test(navigator.userAgent.toLowerCase());
Please sign in to comment.
Something went wrong with that request. Please try again.