3

内部にタイムアウト機能を持つjQueryプラグインを作成しようとしています。これが私が今持っているものの基本的な考えです。正常に動作しますが、連鎖可能性は維持されません。

;(function( $ ) {
    $.fn.myPlugin = function(length) {
        th = $(this);
        th.css('animation', 'none');
        setTimeout((function(th) {
            return function() { 
                th.css('display', 'block');
            };
        })(this), length);
    };
})( jQuery );

連鎖可能にするためにこれを作成しましたが、TimeOut 関数でコードを実行しません。

;(function( $ ) {
    $.fn.myPlugin = function(length) {
        return this.each(function() {
            th = $(this);
            th.css('animation', 'none');
            setTimeout((function(th) {
                return function() { 
                    th.css('display', 'block');
                };
            }),(this), length);
        });
    };
})( jQuery );

チェーンなしで動作するプラグインは次のとおりです: http://jsfiddle.net/FhARs/1/

4

1 に答える 1

1

これは機能しています。これはあなたが望むものですか?

;(function( $ ) {
    $.fn.myPlugin = function(length) {
        return this.each(function() {
            th = $(this);
            th.css('display', 'none');
            setTimeout(function() {
                th.css('display', 'block');
            }, length);
        });
    };
})( jQuery );

デモ

于 2012-10-15T18:48:27.277 に答える