HTML DOM backgroundPositionX 属性

定义和用法

backgroundPositionX 属性设置背景图像的水平位置。

语法:

  1. Object.style.backgroundPositionX=position
参数 描述
- left - center - right 水平位置。
x% 水平位置。左是 0%。右是 100%。
xpos 水平位置。左是 0。单位是像素 (0px) 或其他 CSS 单位。

实例

本例改变了背景图像的水平位置:

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. body
  5. {
  6. background-color:#FFCC80;
  7. background-image:url(bgdesert.jpg);
  8. background-repeat:no-repeat
  9. }
  10. </style>
  11. <script type="text/javascript">
  12. function changePosition()
  13. {
  14. document.body.style.backgroundPositionX="right";
  15. }
  16. </script>
  17. </head>
  18. <body>
  19.  
  20. <input type="button" onclick="changePosition()"
  21. value="Change background-image's x-position" />
  22.  
  23. </body>
  24. </html>