0

I'm not an expert in JavaScript but i have a simple function and is working correctly in all browsers except IE8 and 7

function setSelected() {
    var backgroundPos = $('div.eventJumpToContainer').find('.selected').css('backgroundPosition').split("");
    var xPos = backgroundPos[0];
    var yPos = '-100px';
    var toSet = xPos + ' ' + yPos;
    $('div.eventJumpToContainer').find('.selected').css('backgroundPosition', toSet);
    $('div.eventJumpToContainer span.jumpDate').not('.selected').each(function () {
        var backgroundPos = $(this).css('backgroundPosition').split(" ");
        var xPos = backgroundPos[0];
        $(this).css('backgroundPosition', xPos + ' top');
    });
}

When stepping through this code in IE9:

$('div.eventJumpToContainer').find('.selected').css('backgroundPosition') = ‘3600px 0%’

But in IE8, this expression is null.

I've try a lot of things but i can't get it ! Thanks in advance

Mike Robinson
  • 24,971
  • 8
  • 61
  • 83
kevinblanco
  • 779
  • 2
  • 7
  • 13
  • `backgroundposition`? You mean `background-position`, right? – Pranav 웃 Dec 21 '12 at 19:28
  • 1
    Actually, IE does'nt understand the getter for background-position property, it does however support background-position-x/y ? See this SO answer : http://stackoverflow.com/questions/594870/fix-for-background-position-in-ie – adeneo Dec 21 '12 at 19:28
  • 2
    @PranavKapoor hyphenated CSS properties are translated to camel casing in javascript. – jbabey Dec 21 '12 at 19:30

1 Answers1

0

You are using the javascript syntax for background position in the jQuery css function.

Example:

object.style.backgroundPosition="center"

In CSS the property is actually 'background-position'

Try this:

$('div.eventJumpToContainer').find('.selected').css('background-position') = ‘3600px 0%’

If this doesn't work, you may need to use the -ms-background-position-x -ms-background-position-y properties.

ORION
  • 2,374
  • 2
  • 22
  • 31
  • I fixed !! :) ! i saw the post that @adeneo mention and i used 'if (navigator.appName=='Microsoft Internet Explorer') { var backgroundPos = $('div.eventJumpToContainer').find('.selected').css('backgroundPositionX') + " " + var backgroundPos = $('div.eventJumpToContainer').find('.selected').css('backgroundPositionY'); } else { var backgroundPos = $('div.eventJumpToContainer').find('.selected').css('background-position'); – kevinblanco Dec 21 '12 at 20:35
  • Good to hear! Glad I could help – ORION Dec 21 '12 at 20:37