簡體   English   中英

jQuery動畫回調不起作用

[英]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使用item1item2 像這樣( 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)沒有找到任何東西,那么就什么也不會發生。 這是您的代碼,略作修改。

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);
 });

$("#" + 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM