我似乎无法找到如何添加图像到Javascript。我目前正在创建一个动画,我想要做的就是在动画的开始处,我将添加4个数字,从4个数字到数字,然后逐渐减少到音乐。如何添加图像到javascript
我打算让每个数字都离开页面每个角落的边缘以指示倒计时,但我似乎无法插入任何图像。
我试过使用我在网上找到的代码,但似乎没有任何工作。
有人可以帮助给我确切的代码,我需要将图像放入我的Javascript?
我的代码看起来像这样。
window.onload= function(){
var paper = new Raphael(0, 0, 800, 600);
var backGround = paper.rect(0,0,800,600);
backGround.attr({ fill: "black"});
/* Comment - Add your code here*/
var ball = paper.circle(40,270,10);
var paddleleft = paper.rect(10, 230, 15, 100);
var paddleright = paper.rect(775, 230, 15, 100);
var line = paper.rect(400, 0, 5, 600);
ball.attr({ fill: "white"});
paddleleft.attr({ fill: "white"});
paddleright.attr({ fill: "white"});
line.attr({ fill: "white"});
function bounce_drop1() {
ball.animate({cy: 50 , cx: 750}, 500, 'ease-in', bounce_up1);
}
function bounce_up1() {
ball.animate({cy: 50, cx: 750}, 500, 'ease-out', bounce_drop2);
}
bounce_drop1();
function bounce_drop2() {
ball.animate({cy: 570 , cx: 400}, 500, 'ease-in', bounce_up2);
}
function bounce_up2() {
ball.animate({cy: 50, cx: 50}, 500, 'ease-out', bounce_drop1);
}
};
我不确定把图片放在哪里,但是在下面的帖子后面我试过这个。
var imgSrc = "http://www.pnglogo.com/wp-content/uploads/2015/10/4-Number-Clipart-PNG-02202.png";
var img = new Image();
img.src = imgSrc;
document.getElementById('mygallery').appendChild(img);
但它没有做任何事情,我的意思是说图像是一个变量?
对不起,我是新来使用Javascript和我显然需要“导入位图图像”到我的动画。
什么是“将图像转换为JavaScript”? – CoderPi
你必须提供更多信息。JavaScript本身与图像没有任何关系,所以目前还不清楚“如何将图像添加到Javascript”的含义。你也可以问“如何添加一头大象到JavaScript”。 –
http://stackoverflow.com/help/how-to-ask – Blazemonger