[英]jQuery 3.5.1 callback function in .animate() not working
[英]jQuery Animate Callback not Working
我似乎無法使這個jQuery回調對我有用。 有任何想法嗎? 順便說一句,請不要擔心變量,我有一個專門的項目。
$("#" + 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);
});
對我來說1
不是有效的ID,例如item2
使用item1
和item2
。 像這樣( 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);
});
我假設您的代碼運行正常,並且變量存在問題。 如果$('#'+ circle)沒有找到任何東西,那么就什么也不會發生。 這是您的代碼,略作修改。
$("#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);
});
$("#" + 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.