I have a handful of elements I want to set roll overs on, how ever I am looking to do the calculating on the fly rather than manually setting the position each time for each roll over as over time there will be many. Currently I am using a sprite, that as the time comes I append more to it.. Always side by side, and always 10px padding all around for the per image aspect of it.
So I know if my defualt position is always 0 100 for example and I want to get the roll over for that then I know its going to be 50 100 How can I go about just having a method of taking the 2 values of that but only adding to one of them
You need to grab the background-position and break it into two values, perform the calculation, that set the values back as a string.
myPos = $('.selection').css("background-position").split(" ") myPos <-- will contain the X-value, "50px" myPos <-- will contain the Y-value, "100px"
You then need to turn them into integers: (assume you're doing the same with myPos)
myPos = parseInt(myPos.replace("px",""))
Then you do the math and assign them back:
myPos = myPos + 100 $('.selection').css("background-position", myPos+'px ' + myPos + 'px')