lovo2
lovo2

Reputation: 37

How to background repeat jquery

I'm trying to not repeat background.

Here is my code

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

The problem is that the background repeats. How to fix that ?

Upvotes: 0

Views: 5607

Answers (5)

johnmdonahue
johnmdonahue

Reputation: 653

Have you tried:

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

for dynamically,

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

Upvotes: 0

ThiefMaster
ThiefMaster

Reputation: 318548

Your problem is that background sets all background-related options while background-repeat is just a single one - which is overridden by background.

The best solution is using backgroundImage for the background image and backgroundRepeat for the repetition since that will not touch other background options which might already exist.

Another solution would be setting background to url(...) no-repeat

Upvotes: 0

shernshiou
shernshiou

Reputation: 518

Try this:

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

Upvotes: 0

Jaques le Fraque
Jaques le Fraque

Reputation: 543

Maybe you should give backgroundRepeat: 'no-repeat' a chance.

Upvotes: 1

jerjer
jerjer

Reputation: 8768

use css class:

css:

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

js:

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

Upvotes: 0

Related Questions