1

I want to make no-repeat picture (background) for javascript.

e.target.style.backgroundImage = "url(sozai/a.jpg)";

In this case a.jpg will be shown as a background repeatedly but I want to have no-repeat.

Also I want to make change of transparency of the picture.

NightShadeQueen
  • 3,284
  • 3
  • 24
  • 37
Kevin Suzuki
  • 25
  • 1
  • 7

2 Answers2

5

You can set background-repeat property like

e.target.style.backgroundImage = "url(sozai/a.jpg)";
e.target.style.backgroundRepeat = "no-repeat";

or simplified

e.target.style.background = "url(sozai/a.jpg) no-repeat";
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
1

for no-repeat

e.target.style.backgroundRepeat = "no-repeat";

for transparency

e.target.style.opacity = "0.7"; 
Pavan Teja
  • 3,192
  • 1
  • 15
  • 22
  • 1
    Changing the opacity will also affect everything inside the element, not just the background. But you can use pseudo elements to target exclusively the opacity of the background image. See [this post](http://stackoverflow.com/questions/4997493/set-opacity-of-background-image-without-affecting-child-elements) on how to achieve this. – Joel Kornbluh Sep 01 '15 at 04:14