hm-08042

方法一:    

预先设置好一个样式,当用到的时候,只需要给这个对象添加一个类名就行了。

eg: 

css中:
.bj { background: url(star.jpg) no
-repeat center; background-size: cover; }
js中: oBox.className
= "bj";

方法二:

直接使用JS的元素属性style

1 oBox.style.backgroundImage = "url(star.jpg)";//设置背景图的的地址
2 oBox.style.backgroundRepeat = "no-repeat";//设置背景不平铺
3 oBox.style.backgroundPosition = "center";//设置背景图的位置
4 oBox.style.backgroundSize = "cover";//设置背景图像的尺寸

 

分类:

技术点:

相关文章:

  • 2021-11-03
  • 2021-04-10
  • 2022-12-23
  • 2021-11-24
  • 2021-10-01
  • 2021-04-17
  • 2022-12-23
  • 2022-02-28
猜你喜欢
  • 2022-12-23
  • 2021-05-14
  • 2021-10-20
  • 2021-09-19
  • 2021-07-02
  • 2021-11-19
  • 2021-12-04
相关资源
相似解决方案