J'ai le code suivant.jQuery .animate issue
if ($(checkboxID)[0].checked == false) {
$(this).animate({
'background-position-x': '0%',
'background-position-y': '0%'
}, 200, 'linear');
$(checkboxID)[0].checked = true;
$(this).removeClass('off').addClass('on');
} else {
$(this).animate({
'background-position-x': '100%',
'background-position-y': '0%'
}, 200, 'linear');
$(checkboxID)[0].checked = false;
$(this).removeClass('on').addClass('off');
}
Comme vous pouvez le voir le code est identique dans les deux côtés du si, mais s'il est vrai que le jquery n'anime pas la transition, peu importe à quel point j'augmenter la durée. L'un de vous peut-il voir une erreur ici?
EDIT: Voici le css aussi:
.checkbox-style {
display: block;
width: 87px;
height: 28px;
background: url('images/check-square.png') no-repeat;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
overflow: hidden;
cursor: pointer;
}
.on {
background-position: 0% 0%;
}
.off {
background-position: 100% 0%;
}
Peut être fournir un jsFiddle. –
Vous devez utiliser backgroundPositionX ... mais cela ne fonctionne que dans le chrome, voici une solution multi-navigateur: http://stackoverflow.com/questions/13442897/jquery-animate-backgroundposition-not-working?rq=1 – pathfinder