2012-11-28 73 views
-1

我想要設置:背景圖像,背景大小和背景重複...這裏的語法如何?在預加載器上使用jQuery .css()設置CSS背景圖像

qLpercentage = $("<div id='qLpercentage'></div>").text("0%").css({ 
        height: "40px", 
        width: "100px", 
        position: "absolute", 
        background: 'url(images/preload.gif)', 
        fontSize: "3em", 
        top: "50%", 
        left: "50%", 
        color: "#FFFFFF", 
        marginTop: "-" + (59 + qLoptions.barHeight) + "px", 
        textAlign: "center", 
        marginLeft: "-50px", 
       }).appendTo(qLoverlay); 
+0

你有沒有想過自己做?這個問題實際上是自己回答的。 –

+0

在CSS中你可以背景:url(images/preload.gif)no-repeat ...',' – Valky

回答

0

爲什麼當你的代碼中有靜態屬性時,你想混亂你的JavaScript。

最好讓他們在單獨的並將其添加到您的元素。

這將是更清潔。

這樣你也可以指定background image, background size, and background repeat

CSS

.overlay 
{ 
    height: "40px"; 
    width: "100px"; 
    position: "absolute"; 
    background: 'url(images/preload.gif)' 50% 50% repeat-x ; 
    background-size: 275px 125px; 
    fontSize: "3em"; 
    top: "50%"; 
    left: "50%"; 
    color: "#FFFFFF"; 
    textAlign: "center"; 
    marginLeft: "-50px"; 
}​ 

的Javascript

qLpercentage = 
    $("<div id='qLpercentage'></div>").text("0%") 
    .css({ 
     marginTop: "-" + (59 + qLoptions.barHeight) + "px" 
    }) 
    .addClass('overlay') 
    .appendTo(qLoverlay);​ 
0

嘗試添加此:

"background-image" : "url(my-image.png)", 
    "background-repeat" : "...", 
    "background-size" : "...", 
0

我有我是正確的它是這樣的:

qLpercentage = $("<div id='qLpercentage'></div>").text("0%").css({ 
        height: "40px", 
        width: "100px", 
        position: "absolute", 
        backgroundImage: 'url(images/preload.gif)', 
        backgroundRepeat: 'repeat-x', 
        backgroundSize: '10px 10px', 
        fontSize: "3em", 
        top: "50%", 
        left: "50%", 
        color: "#FFFFFF", 
        marginTop: "-" + (59 + qLoptions.barHeight) + "px", 
        textAlign: "center", 
        marginLeft: "-50px", 
       }).appendTo(qLoverlay);