首页javascriptbackgroundJavascript Style - 如何获取div的背景图像的背景位置

Javascript Style - 如何获取div的背景图像的背景位置

我们想知道如何获取div的背景图像的背景位置。

<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#div {
  background-image: url('http://www.w3cschool.cn/style/download.png');
  background-repeat: no-repeat;
  width: 50px;
  height: 50px;
  background-position: 10px 10px;
}
</style>
</head>
<body>
  <div id="div"></div>
  <script type='text/javascript'>
var d = document.getElementById('div');
console.log(window.getComputedStyle(d).getPropertyValue("background-position"));

</script>
</body>
</html>