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.
Here's my 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 <= 5; i++)
makeClicker(i);
Thanks for any advices on what could cause this. -Simon