0

私はjqueryプラグインが初めてです。必要に応じて scrollWidth を変更できるように、totalWidth をオプションとして指定する必要があります。誰かが私を助けることができますか?

(function( $ ) {
    $.fn.scrollAnimation = function(options) {
            var totalWidth;
            var settings = $.extend( {
                                        'totalWidth'         :'totalWidth'
                                    }, options);

            return this.each(function() {

                    var element = $(this);
                    var offset_1 = $("ul li.list:first-child",element).position().left;
                    var offset_2 = $("ul li.list:nth-child(2)",element).position().left; 
                    var totalWidth =(offset_2-offset_1);





            $(".abc",element).click(function() {
                $(".images",element).not(":animated").animate({"scrollLeft":"-="+totalWidth},300);
                return false;
            });



            $(".def",element).click(function() {
                $(".images",element).not(":animated").animate({"scrollLeft":"+="+totalWidth},300);
                return false;
            });
         });
      };
})( jQuery ); 
4

1 に答える 1

0

このようにプラグインに設定を追加します

$.fn.scrollAnimation.settings={property:'value',totalWidth:'somevalue'};

これがプラグインのデフォルト設定になります。

$ .extendを使用して、ユーザー指定のオプションと$ .fn.scrollAnimation.settingsのプロパティを単一のオブジェクトにマージし、ユーザー指定のオプションを優先することができます。

$.extend({},$.fn.scrollAnimation.settings,options);

したがって、更新されたコードは次のようになります

(function( $ ,win, doc) {
    $.fn.scrollAnimation = function(options) {
            var totalWidth;
            var localsettings = $.extend( {},$.fn.scrollAnimation.settings,options);
                    ...
                    ...
                    ...
                 };

      $.fn.scrollAnimation.settings={property:'value',totalWidth:'somevalue'};
})( jQuery ,window,document,undefined);
于 2012-06-04T07:50:53.667 に答える