我使用的画布,我有这样的代码 -
帆布 - 获取图像位置
var myCanvas = document.getElementById("myCanvas"),
ctx = null;
// Check for support - Feature Support and not Browser Support
if (myCanvas.getContext) {
// Getting the context future 3d ^_^
ctx = myCanvas.getContext("2d");
var googleLogo = new Image();
googleLogo.src = 'img.png';
googleLogo.onload = function(){
// Adding our image..
ctx.drawImage(googleLogo,0,0); // drawImage(image object,x,y)
};
}else{
alert("You don`t have support in CANVAS !");
}
我想使这是一个动画制作(0,0)谷歌标志移动到(0,120)。
理论上我知道我需要使用setInterval和每x秒我需要增加图像的y,但是如何改变图像的y位置?
setInterval(function(){
var imgY = ?; // How I can get my image y?or x?
if(imgY != 120){
imgY += 2; // adding the velocity
}
},250);
谢谢,Yosy。
我想你可以用JavaScript和HTML来做到这一点。不知道你为什么要使用画布。 – 2010-07-09 23:34:06