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 t开发者_运维知识库o fix that ?
Maybe you should give backgroundRepeat: 'no-repeat'
a chance.
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
use css class:
css:
.bg {background:url(../img/bgr.png) no-repeat;}
js:
$('body').addClass('bg');
Try this:
$("body").css({background : "url(../img/bgr.png)", background-repeat: 'no-repeat'});
Have you tried:
$("body").css({background : "url(../img/bgr.png) no-repeat" });
for dynamically,
$("body").css({background : 'url('+imageUrl+') no-repeat' })
精彩评论