hejka
mam taki skrypt http://mylegend.pl
oparty o jquery
i o ile animacja ruchu w lewo prawo jest ładna płynna, to ruch góra duł się ścina
dopiero zaczynam zabawę z jquery i liczę na jakąś pomoc
<script type='text/javascript'>
var xpos = 0;
var ypos = 0;
var stepTime = Date.now()+200;
function goLeft(x){
xpos = xpos + 8;
pos = xpos + "px "+ ypos+ "px";
$('#bg').animuj({"backgroundPosition": pos },{
duration:'fast',
step:function(){
if(stepTime < Date.now()){
document.getElementById("block").style.backgroundImage = "url(l"+(9-x)+".png)";
stepTime = Date.now()+200;
}
},
complete:function(){
if(x == 0) { document.getElementById("block").style.backgroundImage = "url(6.png)"; }
}
});
x--;
if(x >= 0){
goLeft(x);
}
}
function goRight(x){
xpos = xpos - 8;
pos = xpos + "px "+ ypos+ "px";
$('#bg').animuj({"backgroundPosition": pos },{
duration:'fast',
step:function(){
if(stepTime < Date.now()){
document.getElementById("block").style.backgroundImage = "url(r"+(9-x)+".png)";
stepTime = Date.now()+200;
}
},
complete:function(){
if(x == 0) { document.getElementById("block").style.backgroundImage = "url(6.png)"; }
}
});
x--;
if(x >= 0){
goRight(x);
}
}
function goUp(x){
ypos = ypos + 8;
pos = xpos + "px "+ ypos+ "px";
$('#bg').animuj({"backgroundPosition": pos },{
duration:'fast',
step:function(){
if(stepTime < Date.now()){
document.getElementById("block").style.backgroundImage = "url(u"+(9-x)+".png)";
stepTime = Date.now()+200;
}
},
complete:function(){
if(x == 0) { document.getElementById("block").style.backgroundImage = "url(6.png)"; }
}
});
x--;
if(x >= 0){
goUp(x);
}
}
function goDown(x){
ypos = ypos - 8;
if(ypos > 0) { pos = (xpos + 8) + "px "+ (ypos)+ "px"; }
else { pos = xpos + "px "+ (ypos)+ "px"; }
if(x > 0){
$('#bg').animuj({"backgroundPosition": pos },{
duration:'fast',
step:function(){
if(stepTime < Date.now()){
document.getElementById("block").style.backgroundImage = "url(d"+(9-x)+".png)";
stepTime = Date.now()+200;
}
},
complete:function(){
if(x == 0) { document.getElementById("block").style.backgroundImage = "url(6.png)"; }
}
});
x--;
goDown(x);
}
}
function handleArrowKeys(evt) {
evt = (evt) ? evt : ((window.event) ? event : null);
if (evt) {
switch (evt.keyCode) {
case 37:
goLeft(8);
break;
case 38:
goUp(8);
break;
case 39:
goRight(8);
break;
case 40:
goDown(8);
break;
}
}
}
document.onkeyup = handleArrowKeys;
</script>