Ich habe das. (Abgekürzt für diesen Beitrag nach unten nicht sinnlos Füllstoff sein):Wie benutze ich jquery, um ein Hintergrundbild beim Anklicken einer URL in einem Array zu ändern?
var randomQuote = function() {
var quotes = [{
author: "Duke Nukem: Manhatten Project",
quote: "Come on out, Morphix. There's just two ways this can end, and in both of them, you die!",
boxart: "http://game-server-hosting.net/wp-content/uploads/2008/12/4235.jpg"
}];
var numQuotes = quotes.length;
var randomIndex = Math.round(Math.random() * numQuotes);
var quotation = quotes[randomIndex - 1];
$('.quotebox').html(quotation.quote);
$('.authorbox').html(quotation.author);
};
Ich verstehe, wie so etwas funktioniert:
$('#bg').css({backgroundImage: "url("+imgbg+")"});
Was ich wissen will, ist, wie ich stattdessen machen, wo das Hintergrundbild ändert sich von dem, was dort ist, zu dem Boxart-Teil des Arrays anstelle einer einfachen URL? Benutze ich quotation.boxart? Und wenn ja, wie? Ich habe ein paar Möglichkeiten ausprobiert, die keine Arbeit scheinen:
$('body').css({'background-image': quotation.boxart});
$('body').css({'background-image': 'quotation.boxart'});
$('body').css({'background-image': 'url(quotation.boxart)'});
Wenn es gibt einen anderen Weg, ich weiß noch nicht, jede mögliche Hilfe würde geschätzt (da ich nur zu lernen), danke!
'$ ('body') verwenden CSS ({ 'background-image': 'url (' + quotation.boxart + ')'});.' –
Ah hah! Ich brauchte die + drin. Ich danke dir sehr! – Joseph