javascript - How to get xpos of a div's background image? -
i have simple script meant console.log xpos of div's background image console shows blank.
this have:
var d = document.getelementbyid('div'); console.log(d.style.backgroundposition); //shows blank line console.log(d.style.backgroundposition.xpos); //undefined (obviously) i'm curious why backgroundposition coming out blank though?
the div's css is:
#div{ background-image: url('test.png'); background-repeat: no-repeat; width:50px; height:50px; background-position: 0px 0px; } the html requested:
<body> <div id="div"></div> </body> any ideas ?
the format console.log(d.style.backgroundposition); works styles set inline. styles set via style sheet, use getcomputedstyle:
window.getcomputedstyle(d).getpropertyvalue("background-position"); // returns 0px 0px if want x or y position, use "background-position-x" or "background-position-y".
Comments
Post a Comment