Search code examples
javascriptcssprototypejsbackground-imagebackground-position

How do I get just the x or y position of the background image using prototype?


Hey, I'm making a simple user friendly css editor using Prototype. Anyway, I was wondering whether I could get the background-position x/y values on their own?

I wish I could do something like this but sadly it doesn't work: element.getStyle('background-position-x);

I guess this is because position comes in different forms like 'center' rather than just being generic.


Solution

  • Hey, this seemed to work pretty well. Even when the position is set to 'center center' prototype will translate this into percentages! Very handy!

    var temp = $('header').getStyle('background-position');
    var split = temp.split(" ");
    $('header_horizontal_position').value = split[0];
    $('header_vertical_position').value = split[1];
    

    Anyway, thanks for the help guys.