我似乎無法找到如何添加圖像到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