Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground positioning with jquery doesn't work in IE7
    text
    copied!<p>My script is supposed to dynamically change the background-position when clicking on a button (adding or substracting 1 percent from the current value). Works fine in Fx and Chrome, and ie8 too (i believe), though not in ie7.</p> <p>Here's my code:</p> <pre><code>function makeClicker(index) { $('#leftbutton' + index).click(function() { var bPos = $('#div' + index).css('background-position'); bPos = bPos.replace(/%/g, '').split(' '); var bPosResult = (1 + parseInt(bPos[0], 0)); bPos = bPosResult + '% ' + bPos[1] + '%'; $('#div' + index).css('background-position', bPos); $('#vposition' + index).attr("value", bPosResult + '%'); }); $('#rightbutton' + index).click(function() { var bPos = $('#div' + index).css('background-position'); bPos = bPos.replace(/%/g, '').split(' '); var bPosResult = (-1 + parseInt(bPos[0], 0)); bPos = bPosResult + '% ' + bPos[1] + '%'; $('#div' + index).css('background-position', bPos); $('#vposition' + index).attr("value", bPosResult + '%'); }); $('#upbutton' + index).click(function() { var bPos = $('#div' + index).css('background-position'); bPos = bPos.replace(/%/g, '').split(' '); var bPosResult = (1 + parseInt(bPos[1], 0)); bPos = bPos[0] + '% ' + bPosResult + '%'; $('#div' + index).css('background-position', bPos); $('#hposition' + index).attr("value", bPosResult + '%'); }); $('#downbutton' + index).click(function() { var bPos = $('#div' + index).css('background-position'); bPos = bPos.replace(/%/g, '').split(' '); var bPosResult = (-1 + parseInt(bPos[1], 0)); bPos = bPos[0] + '% ' + bPosResult + '%'; $('#div' + index).css('background-position', bPos); $('#hposition' + index).attr("value", bPosResult + '%'); }); } for(var i = 1; i &lt;= 5; i++) makeClicker(i); </code></pre> <p>Thanks for any advices on what could cause this. -Simon</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload