JavaScript 参考手册
Style backgroundPosition 属性
更改背景图像的位置
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <style> div { background-image: url("/examples/img_tree.png"); background-repeat: no-repeat; width: 400px; height: 400px; border: 1px solid #000000; } </style> <script> function displayResult() { document.getElementById("div1").style.backgroundPosition = "center bottom"; } </script> </head> <body> <button type="button" onclick="displayResult()">修改背景图像位置</button> <br> <div id="div1"> </div> </body> </html>
运行结果:
点击运行 »