0


外部ファイルからJSONデータを取得して「div#slider」に追加するプラグインがあります。データは取得されて正常に機能していますが、データを正常に取得した後、easySliderが初期化されません。スライドは開始されません。http://lkamal.com.np/r3dImage

に コードがあります。プラグインコードは次のとおりです。

(function($) {

    $.fn.r3dImage = function(options){
    var defaults = {
        url:        'ajax/test.txt',
        pause:      2000,

    }; 

    var options = $.extend(defaults, options);
    //retrive json file
    return this.each(function() {  
        obj = $(this);  
        var body = obj.html();
        getJson();
    });

    function getJson(){
        $.ajax({
       type: "POST",
       url: options.url,
       dataType: "json",
       cache: false,
       contentType: "application/json",
       success: function(data) {
        //alert("Success");
       $.each(data.dashboard, function(i,post){

            obj.html('<li><a href="'+post.TargetUrl+'" target="'+post.Target+'"><img src="' + post.ImageUrl + '" title="' + post.OverlayText +'" /></a></li>');

        });
        $(obj).easySlider({
            pause: options.pause
        });
      },
        error: function(xhr, status, error) {
            alert(xhr.status);
        }
    });
    };
/*  this.each(function() {
        $(options.container).easySlider({
            pause: options.pause
        });
    });*/
    };

})(jQuery);

もう1つは簡単なスライダー1.7です。
または
、easysliderプラグイン内で実行できますか。
この2つのプラグインをマージして1つ作成するにはどうすればよいですか。

4

1 に答える 1

0

私もこれに対する解決策を得ました。

$(function() {
    $.fn.r3dImage = function(param) {
        var options = {
            url : "",
            pause : 2000,
            feedFetchDelay : 10
        };

        this.each(function() {
            var element = $(this);
            //alert(element.attr('id'));
            element.html("<ul></ul>");
            options = $.extend(options,param);
            if(options.url=="") { console.log("URL is not specified"); }
            else {
                getJsonFeed(element);   //retrives json feed and appends to respective div
                setInterval(getJsonFeed, options.feedFetchDelay*1000*60);   //Time interval in milli seconds converted to minute using delay*1000*60
            }
        });

        function getJsonFeed(element){
            //function to retrive json feed start using post of json data
            $.post(
                options.url,
                function(data) {
                    //alert(data.dashboard);

                    html = '';
                    $.each(data.dashboard, function(k,v) {
                       html += '<li>';
                       html += '<a href="'+v.TargetUrl+'" target="'+v.Target+'">';
                       html += '<img src="' + v.ImageUrl + '" alt="' + v.Alt +'" title="' + v.OverlayText +'" />';
                       html += '</a><p>'+v.OverlayText+'</p></li>';                           
                    });
                    //alert(html);
                    $("ul", element).append(html); //appending the json data with respective div
                    //initialize the slider to easy slider
                    $(element).easySlider({
                        auto: true, 
                        continuous: true
                    });
                },
                "json"
            );
        }
    }    
});
于 2011-06-09T09:06:15.223 に答える