I created a code that it work as a "movie" because the "pellicle" is a long image that contain all iphone movement. For create a sense of movement as movie, this code add 500px on the backgroundPositionY, then it wait 30 ms and restarts this process.
The mechanism is simple but the code is too long especially when will use a function .toggle() that is serves for add an another function, that it create an opposite animation when you do another click.
/*animate*/
screen.toggle(function(e){
var mov = 0;
function cicloIphone(){
if(mov>6000){
mov=0;
};
iphone.css('backgroundPosition', '0 -'+mov+'px');
mov += 500;
if(mov<6000){
window.setTimeout(function(){
cicloIphone();
}, 30);
};
};
var timeoutIphone = window.setTimeout(function(){
cicloIphone();
},0);
},function(e){
var mov = 5500;
function cicloIphone(){
if(mov>6000){
mov=0;
};
iphone.css('backgroundPosition', '0 -'+mov+'px');
mov -= 500;
if(mov<6000){
window.setTimeout(function(){
cicloIphone();
}, 30);
};
};
var timeoutIphone = window.setTimeout(function(){
cicloIphone();
},0);
});
I want synthesize with the function animate() but not ricreate my effect because not jump from 500px than 1000px each 30ms, but is too fluid and increase pixel for pixel.
/*animate synthesized*/
screen.toggle(
function(e){iphone.stop(true,true).animate({
'backgroundPositionX':'0px',
'backgroundPositionY':'-5500px'
},3000)},function(e){iphone.stop(true,true).animate({
'backgroundPositionX':'0px',
'backgroundPositionY':'0px'
},3000);
});