2011-06-28 31 views
0

我試圖不重複背景。如何後臺重複jquery

這裏是我的代碼

$("body").css({background : "url(../img/bgr.png)", backgroundRepeat: 'none'}); 

的問題是,背景重複。如何解決這個問題?

回答

0

您的問題是background套,而background-repeat所有背景有關的選項,只是一個單一的一個 - 這是由background覆蓋。

最好的解決辦法是使用backgroundImage作爲背景圖像,使用backgroundRepeat作爲重複,因爲它不會觸及其他可能已存在的背景選項。

另一個解決方案是設置backgroundurl(...) no-repeat

+0

感謝 我會在四分鐘內投 – lovo2

+0

你不必等待upvoting - 只爲接受的答案;) – ThiefMaster

0

你試過:

$("body").css({background : "url(../img/bgr.png) no-repeat" }); 

用於動態,

$("body").css({background : 'url('+imageUrl+') no-repeat' }) 
0

使用CSS類:

CSS:

.bg {background:url(../img/bgr.png) no-repeat;} 

JS:

$('body').addClass('bg'); 
1

也許你應該給backgroundRepeat: 'no-repeat'一個機會。

0

試試這個:

$("body").css({background : "url(../img/bgr.png)", background-repeat: 'no-repeat'});