Permalink
Browse files

merge

  • Loading branch information...
1 parent 0bb375d commit 2b0ed9bf3ffa5778a84cd166188534f8199634fc CodeHunger committed Aug 8, 2012
Showing with 103 additions and 41 deletions.
  1. +24 −11 source/controllers/scroll.js
  2. +79 −30 source/jarallax.js
@@ -3,16 +3,17 @@
////////////////////////////////////////////////////////////////////////////////
ControllerScroll = function(smoothing, scrollSpace) {
this.target = $(window);
+ $(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();
}
-
+
this.smoothing = smoothing || false;
-
+
this.targetProgress = 0;
};
@@ -30,12 +31,24 @@ ControllerScroll.prototype.deactivate = function(jarallax) {
ControllerScroll.prototype.onScroll = function(event) {
var controller = event.data.scope;
-
+
+ if(controller.jarallax.jumping){
+ if(!controller.jarallax.jumping_allowed) {
+ controller.jarallax.clearSmooth(controller.jarallax);
+ }
+
+ //console.log('preventing default');
+ //event.preventDefault();
+ //return false;
+ }
+
+
+
if (controller.isActive) {
var y = event.data.y || controller.target.scrollTop();
var progress = y/controller.scrollSpace;
-
-
+
+
if(!controller.smoothing){
controller.jarallax.setProgress(progress, true);
} else {
@@ -54,13 +67,13 @@ ControllerScroll.prototype.smooth = function(externalScope) {
}
var oldProgress = scope.jarallax.progress;
-
+
var animationSpace = scope.targetProgress - oldProgress;
clearTimeout(scope.timer);
-
+
if(animationSpace > 0.0001 || animationSpace < -0.0001){
var newProgress = oldProgress + animationSpace / 5;
-
+
scope.timer = window.setTimeout(function(){
scope.smooth(scope);}, scope.jarallax.FPS_INTERVAL);
scope.jarallax.setProgress(newProgress, true);
@@ -71,8 +84,8 @@ ControllerScroll.prototype.smooth = function(externalScope) {
ControllerScroll.prototype.update = function(progress) {
var scrollPosition = progress * this.scrollSpace;
-
+
if(!this.jarallax.allowWeakProgress) {
- $('body').scrollTop(scrollPosition);
+ $(window).scrollTop(scrollPosition);
}
};
View
@@ -18,6 +18,7 @@ var Jarallax = function (controller) {
this.allowWeakProgress = true;
this.frameRate = this.FPS;
this.stepSize = 0;
+ this.jumping = false;
if (controller === undefined) {
if($.browser.iDevice){
@@ -42,7 +43,7 @@ var Jarallax = function (controller) {
for (var i in this.controllers) {
this.controllers[i].activate(this);
}
-
+
this.frameChart = [];
for(var j = 1; j <= 600; j++) {
this.frameChart[j] = (1000 / j);
@@ -57,7 +58,10 @@ Jarallax.prototype.setProgress = function (progress, isWeak) {
progress = 1;
} else if (progress < 0) {
progress = 0;
+ }else{
+ progress = Math.round(progress * 1000) / 1000;
}
+<<<<<<< HEAD
this.prev_progress = this.progress;
this.progress = progress;
if(this.prev_progress !== progress) {
@@ -79,6 +83,30 @@ Jarallax.prototype.setProgress = function (progress, isWeak) {
this.controllers[controller].update(this.progress);
}
+=======
+
+ if(this.progress != progress){
+ this.progress = progress;
+ if (this.allowWeakProgress || !weak) {
+ this.previousTime = new Date();
+
+ this.currentTime = new Date();
+
+ var weak = isWeak || false;
+
+ for (var defaultValue in this.defaultValues) {
+ this.defaultValues[defaultValue].activate(this.progress);
+ }
+
+ for (var animation in this.animations) {
+ this.animations[animation].activate(this.progress);
+ }
+
+ for (var controller in this.controllers) {
+ this.controllers[controller].update(this.progress);
+ }
+
+>>>>>>> adba2cf... Fixed firefox broken scroll bar. Fixed bug which only implements default values
this.currentTime = new Date();
this.stepSize = Math.max(this.currentTime - this.previousTime, this.stepSize);
}
@@ -103,24 +131,28 @@ Jarallax.prototype.jumpToProgress = function (progress, time, fps) {
} else if (progress.indexOf('%') != -1) {
progress = parseFloat(progress) / 100;
}
-
+
+ if(progress == this.progress) {
+ return false;
+ }
+
if (progress > 1) {
progress = 1;
} else if (progress < 0) {
progress = 0;
}
-
+
this.smoothProperties = {};
this.smoothProperties.timeStep = 1000 / fps;
this.smoothProperties.steps = time / this.smoothProperties.timeStep;
this.smoothProperties.currentStep = 0;
-
+
this.smoothProperties.startProgress = this.progress;
this.smoothProperties.diffProgress = progress - this.progress;
this.smoothProperties.previousValue = this.progress;
this.smooth();
this.allowWeakProgress = false;
-
+
return false;
};
@@ -131,7 +163,7 @@ Jarallax.prototype.smooth = function (externalScope) {
} else {
scope = externalScope;
}
-
+
scope.smoothProperties.currentStep++;
clearTimeout(scope.timer);
if (scope.smoothProperties.currentStep < scope.smoothProperties.steps) {
@@ -141,23 +173,32 @@ Jarallax.prototype.smooth = function (externalScope) {
scope.smoothProperties.diffProgress,
1,
5);
-
+
+ scope.jumping_allowed = true;
scope.setProgress(newProgress);
+ scope.jumping_allowed = false;
scope.timer = window.setTimeout(function(){scope.smooth(scope);}, scope.smoothProperties.timeStep);
scope.smoothProperties.previousValue = newProgress;
scope.allowWeakProgress = false;
} else {
- scope.allowWeakProgress = true;
+ scope.jumping_allowed = true;
scope.setProgress(scope.smoothProperties.startProgress + scope.smoothProperties.diffProgress);
- delete scope.smoothProperties;
+ scope.jumping_allowed = false;
+ scope.clearSmooth(scope);
}
};
+Jarallax.prototype.clearSmooth = function(scope){
+ scope.allowWeakProgress = true;
+ clearTimeout(scope.timer);
+ delete scope.smoothProperties;
+};
+
Jarallax.prototype.setDefault = function (selector, values) {
if (!selector) {
throw new Error('no selector defined.');
}
-
+
if (JarallaxTools.isValues(values))
{
var newDefault = new JarallaxObject(selector, values);
@@ -170,7 +211,7 @@ Jarallax.prototype.addStatic = function (selector, values) {
if (!selector) {
throw new Error('no selector defined.');
}
-
+
if (JarallaxTools.isValues(values))
{
var newDefault = new JarallaxStatic(selector, values[0], values[1]);
@@ -184,7 +225,7 @@ Jarallax.prototype.addCounter = function (properties) {
Jarallax.prototype.addController = function (controller, activate) {
this.controllers.push(controller);
-
+
if (activate) {
controller.activate(this);
}
@@ -198,14 +239,14 @@ Jarallax.prototype.addAnimation = function (selector, values, platforms, allMust
} else {
platforms = platforms || [JarallaxTools.Platform.Any];
}
-
+
if (JarallaxTools.PlatformAllowed(platforms, allMustBeTrue)) {
var newAnimation;
-
+
if (!selector) {
throw new Error('no selector defined.');
}
-
+
var returnValue = [];
if (JarallaxTools.isValues(values)) {
if (values.length) {
@@ -237,14 +278,14 @@ Jarallax.prototype.addAnimation = function (selector, values, platforms, allMust
values.progress = '100%';
}
var startValues = {};
-
+
for (var j in values) {
startValues[j] = $(selector).css(j);
}
-
+
startValues.progress = '0%';
-
-
+
+
newAnimation = new JarallaxAnimation(selector, startValues, values, this);
this.animations.push(newAnimation);
returnValue.push(newAnimation);
@@ -259,52 +300,60 @@ Jarallax.prototype.cloneAnimation = function (selector, adittionalValues, animat
if (!selector) {
throw new Error('no selector defined.');
}
-
+
var newAnimations = [];
var adittionalValuesArray = [];
-
+
for (var i = 0; i < animations.length + 1; i++) {
if (adittionalValues instanceof Array) {
adittionalValuesArray.push(adittionalValues[i]);
} else {
- adittionalValuesArray.push(adittionalValues);
+ adittionalValuesArray.push(adittionalValues);
}
}
-
+
for (i = 0; i < animations.length; i++) {
var currentAnimation = animations[i];
var newStart = JarallaxTools.clone(currentAnimation.startValues);
var newEnd = JarallaxTools.clone(currentAnimation.endValues);
-
+
var adittionalValueStart = adittionalValuesArray[i];
var adittionalValueEnd = adittionalValuesArray[i + 1];
-
+
for (var j in newStart) {
if (adittionalValueStart[j]) {
newStart[j] = JarallaxTools.calculateNewValue(adittionalValueStart[j], newStart[j]);
}
}
-
+
for (var k in newEnd) {
if (adittionalValueEnd[k]) {
newEnd[k] = JarallaxTools.calculateNewValue(adittionalValueEnd[k], newEnd[k]);
}
}
-
+
newAnimations.push(this.addAnimation(selector, [newStart, newEnd])[0]);
-
+
}
return newAnimations;
};
+<<<<<<< HEAD
+=======
+Jarallax.prototype.addImageSequence = function(container, imageName, leadingNumbers, callback){
+ //TODO
+ return false;
+};
+
+>>>>>>> adba2cf... Fixed firefox broken scroll bar. Fixed bug which only implements default values
////////////////////////////////////////////////////////////////////////////////
// Jarallax static methods /////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Jarallax.EASING = {
'linear':function (currentTime, beginningValue, changeInValue, duration, power) {
return currentTime / duration * changeInValue + beginningValue;
},
-
+
'easeOut':function (currentTime, beginningValue, changeInValue, duration, power) {
if (power === undefined) {
power = 2;
@@ -329,7 +378,7 @@ Jarallax.EASING = {
currentTime = currentTime - duration;
return ((Math.pow((duration - currentTime) / duration, power) * -1) + 1) * changeInValue + beginningValue + changeInValue;
}
-
+
return Math.pow(currentTime / duration, power) * changeInValue + beginningValue;
}
};

0 comments on commit 2b0ed9b

Please sign in to comment.