/    Sign up×
Community /Pin to ProfileBookmark

Strange IE Javascript-CSS Issue

Nothing should be labeled as “strange” when it comes to IE anymore, but I find this one particularly peculiar.

Here’s the CSS:

[code]
#header li a {
display: block;
padding: 15px 30px 5px 0;
text-transform: uppercase;
color: #000;
font-family: helvetica,arial,sans-serif;
background: url(layout/pngsprites.png) -160px -232px no-repeat;
}
[/code]

Here’s the Javascript (using jQuery) where elem is a jquery object reference the #header li a element:
[code
var bgpos_ = elem.css(‘backgroundPosition’).split(” “);
[/code]

Works fine in browsers other than IE. So I went a bit deeper into it, I tried specifically declaring the background-position property in the CSS in hopes that IE could find it:

[code]
background: url(layout/pngsprites.png) -160px -232px no-repeat;
background-position: -160px -232px;
[/code]

But nothing….then I even tried using plain old JS to get it using the style property:

[code]
alert(elem.get(0).style.backgroundPositiong);
[/code]

But IE still played foul.

I googled around, figuring this was a common issue, but I haven’t found anything……what’s the fix?

EDIT: [url]http://stackoverflow.com/questions/594870/fix-for-background-position-in-ie[/url]

Apparently it only supports the non-standard background-position-[x|y]

Final code (again in jQuery):

[code]
this.bgy = (elem.css(‘background-position-x’)) ? parseInt(elem.css(‘background-position-y’)) : parseInt(elem.css(‘backgroundPosition’).split(” “)[1]);
[/code]

to post a comment
JavaScript

1 Comments(s)

×

Success!

Help @aj_nsc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...