Skip to content

Instantly share code, notes, and snippets.

@ericwwsun
Created June 26, 2012 20:53
Show Gist options
  • Save ericwwsun/2998882 to your computer and use it in GitHub Desktop.
Save ericwwsun/2998882 to your computer and use it in GitHub Desktop.
Javascript: Background Position control by js, IE8 included
var backgroundPos,
xPos,
yPos;
if( $j("html").hasClass("ie8")) { // html class... you know... it's useful
xPos = $j(this).css("background-position-x");
yPos = Number($j(this).css("background-position-y").replace(/[^0-9-]/g, ''));
} else {
backgroundPos = $j(this).css("backgroundPosition").split(" ");
xPos = backgroundPos[0],
yPos = Number(backgroundPos[1].replace(/[^0-9-]/g, ''));
}
yPos = yPos + 310; // this value will be the y shift distance in your background image
$j(this).css("backgroundPosition", xPos + " " + yPos+ "px");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment