HTML DOM backgroundPositionX 属性
定义和用法
backgroundPositionX 属性设置背景图像的水平位置。
语法:
- Object.style.backgroundPositionX=position
参数 | 描述 |
---|---|
- left - center - right | 水平位置。 |
x% | 水平位置。左是 0%。右是 100%。 |
xpos | 水平位置。左是 0。单位是像素 (0px) 或其他 CSS 单位。 |
实例
本例改变了背景图像的水平位置:
- <html>
- <head>
- <style type="text/css">
- body
- {
- background-color:#FFCC80;
- background-image:url(bgdesert.jpg);
- background-repeat:no-repeat
- }
- </style>
- <script type="text/javascript">
- function changePosition()
- {
document.body.style.backgroundPositionX="right";
- }
- </script>
- </head>
- <body>
- <input type="button" onclick="changePosition()"
- value="Change background-image's x-position" />
- </body>
- </html>