Created
August 23, 2015 10:56
-
-
Save ms2sato/bf11ed9034a94af9a03a to your computer and use it in GitHub Desktop.
animation and deferred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
function test01() { | |
console.log('test01'); | |
var d = new $.Deferred(); | |
$('#box').on('webkitAnimationEnd', function(){ | |
d.resolve(); // ここはanimationが終了したら呼ばれる。resolveを呼ぶと次のdeferredへ処理が移る | |
}).addClass('move01'); | |
return d.promise(); | |
} | |
function test02() { | |
console.log('test02'); | |
var d = new $.Deferred(); | |
$('#box').removeClass('move01'); | |
$('#box').on('webkitAnimationEnd', function(){ | |
d.resolve(); // ここはanimationが終了したら呼ばれる。resolveを呼ぶと次のdeferredへ処理が移る | |
}).addClass('move02'); | |
return d.promise(); | |
} | |
function test03() { | |
console.log('test03'); | |
$('#box').removeClass('move02'); | |
} | |
function playAnimation(){ | |
var promise = Promise.resolve(); | |
promise.then(test01).then(test02).then(test03).then(function(){ | |
console.log('callbacked') | |
}).catch(function(error){ | |
console.error(error); | |
}); | |
} | |
//ボタン | |
$('button').on('click',function(){ | |
playAnimation(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment