jqueryコマンドの間に遅延$.fn
を持たせるためにオブジェクトを拡張したい:
この動作する(そしてかなり長い)コードのように:
$('.d').delay(1000).queue(
function ()
{
$(this).css('background-color', 'green');
$(this).dequeue();
}).delay(1000).queue(function ()
{
$(this).css('background-color', 'red');
$(this).dequeue();
});
実用的なサンプルはこちら:JSBIN
だから私はこれを試しました:
$.fn.myWait = function (ms)
{
return this.queue(
function ()
{
var _self = this;
setTimeout(function ()
{
$(_self).dequeue();
}, ms);
})
};
呼び出し:
$('.d').myWait(1000).css('background-color', 'red').myWait(1000).css('background-color', 'green');
しかし、それは機能しません。
私は何を間違っているのですか?
ps 私はこの同様の解決策を読みましたが、アニメーション部分を削除してcssのみを使用すると、それも機能しません。