if ($("#canvas").css('background-image') == 'url(images/endOfGame.jpg)') {
不工作的时候写的完整路径。但这:有检查的背景图像的JavaScript
var element = document.getElementById('canvas');
var style = window.getComputedStyle(element);
var imagex = style.getPropertyValue('background-image');
console.log(imagex);
if (imagex === "url(file:///C:/Users/Jack/Documents/myGames/Pong/images/endOfGame.jpg)") {
,这并不:
var element = document.getElementById('canvas');
var style = window.getComputedStyle(element);
var imagex = style.getPropertyValue('background-image');
console.log(imagex);
if (imagex === "url(images/endOfGame.jpg)") {
为什么呢?我必须为每台运行我的游戏的计算机更改完整的文件路径代码。不好。
谢谢。
什么'如果(代码imagex ===“图像/ endOfGame.jpg”){' – tymeJV
难道你们就不能只是一个相对路径工作? – putvande
我们可以看到你的目录结构吗? – Austen