Notify after async task is done

后端 未结 2 2034

I\'m building a game with move.js for animation, but it takes too long so when the player click on the right solution it displays the winning message before the rig

2条回答
  •  生来不讨喜
    2021-01-27 20:34

    Edit, Added callback function to .end() to include deferred.notify . See comments , Move#end([fn])

    Try

    var deferred = new $.Deferred();
    click(e); // `e` undefined ?
    deferred.progress(function(msg) {
    // `this` within `deferred`
    // references `deferred` object ,
    // try `obj.checkWin()`, `obj.nextLevel()`
      if (obj.checkWin()) {
        alert(msg);
        obj.nextLevel();
      }
    });
    
    function click(e) {
        // `e` undefined ?
        move(e)
        .set('background-color','black')
        // `.delay()` accepts `number` as argument ? 
        .delay('0.1s')
          // see comments , 
          // http://visionmedia.github.io/move.js/#example-11
        .end(function() {
          deferred.notify("you won !");
        });
    };
    

    jsfiddle http://jsfiddle.net/guest271314/4Av4Z/

提交回复
热议问题