[英]jQuery Animate Callback not Working
I can't seem to get this jQuery callback to work for me. 我似乎无法使这个jQuery回调对我有用。 Any ideas? 有任何想法吗? BTW, please don't worry about the variables, I have a special project this is for. 顺便说一句,请不要担心变量,我有一个专门的项目。
$("#" + circle - 1).animate({
opacity: 0,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000, function() {
$("#" + circle).animate({
opacity: 1,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000);
});
For me 1
is not a valid ID, use item1
and item2
too for instance. 对我来说1
不是有效的ID,例如item2
使用item1
和item2
。 Like this ( http://jsfiddle.net/balintbako/XSGN8/ ): 像这样( http://jsfiddle.net/balintbako/XSGN8/ ):
var circle = 2;
$("#item" + (circle - 1)).animate({
opacity: 0,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000, function () {
$("#item" + circle).animate({
opacity: 1,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000);
});
I would assume that your code is working just fine and there IS something wrong with your variables. 我假设您的代码运行正常,并且变量存在问题。 If $('#' + circle) doesn't find anything then nothing else will happen. 如果$('#'+ circle)没有找到任何东西,那么就什么也不会发生。 Here is your code working, slightly modified. 这是您的代码,略作修改。
http://jsfiddle.net/qbtDj/1/ http://jsfiddle.net/qbtDj/1/
$("#mydiv").animate({
opacity: 0,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000, function() {
$("#mydiv" ).animate({
opacity: 1,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000);
});
Either you have an issue in $("#" + circle - 1)
which i am not sure what you are trying to deduct 1 from but I guess your id is a number which will fail with NAN
during the calculation "#" + circle - 1
so change it to "#" + (circle - 1)
and try: $("#" + circle - 1)
有一个问题,我不确定您要从中扣除1的问题,但我想您的ID是一个在计算"#" + circle - 1
将以NAN
失败的数字"#" + circle - 1
因此将其更改为"#" + (circle - 1)
然后尝试:
$("#" + (circle - 1)).animate({ //<- here use () to seperate the number calculation otherwise it will be NAN.
opacity: 0,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000, function() {
$("#" + circle).animate({
opacity: 1,
"margin-top": "50",
height: '150px',
width: '150px'
}, 1000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.