I have a scroll event that checks for the scroll position and triggers an animation if its passed a certain position. This works nicely until I try it with different browser heights. Then my numbers are off. How can I keep my code and alter it so it works for different browser heights.
Here is the shell of my code.
runStatus is where my animations are set. p is the position point. Now when I test in taller browsers the p value comes in later then when I test in shorter browser heights. Without having to re-write this whole thing I'm trying to see if there is something I can do to compensate for all browser heights.
I also tried using a percentage but it still doesn't trigger consistently if the browser is short or tall.
$(window).scroll(function () {
topScroll = $(this).scrollTop();
run();
});
function run(){
for (var i=0; i < animData.length; i++) {
update(animData[i]);
};
}
function update(obj){
var target = obj.target;
var step = obj.runStatus.length;
if(topScroll < obj.runStatus[0].p){
step = 0;
};
switch(step){
case 0:
//if(obj.repeat) change(target,obj.runStatus[step]);
break;
case obj.runStatus.length:
change(target,obj.runStatus[1]);
break;
}
}
function change(t,a,b){
if(!t.data("complete")) animateTo(a,t);
}
function animateTo(a,t){
t.animate( { left:a.x, top:a.y, opacity:a.opacity }, { duration: 600, easing: easing});
}
var animData =[
// scene 1
{
scene:"#scene1",
name:"#compass",
runStatus:[
{p:220, y:500, opacity:0},
{y:22, opacity:1}
]
},
{
scene:"#scene1",
name:"#chess-right",
runStatus:[
{p:260, y:600, opacity:0},
{y:493, opacity:1}
]
}
]