Jump to content

Manipulating Background Position.


Shade
 Share

Recommended Posts

var a =  document.getElementById('mydiv').style.BackgroundPosition;

returns "10px 20px", probably a string. so, how to get x and y values for two variables ?like var x = x-position(10) var y = y-position(20)as integers to manipulate with ??a little function to extract and assign the two integer values to my choice of variables ??

Link to comment
Share on other sites

var s =  document.getElementById('mydiv').style.backgroundPosition;x = s.substr(0, s.indexOf("px"));y = parseInt(s.substr(s.indexOf(" ")));

That does what you want. You haven't explained what you want it for, but I have a strong suspicion there is a better way to do it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...