2012-06-04 9 views
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); 
+0

무엇이 질문입니까? jsfiddle.net – charlietfl

+0

@AnujJain에서 데모 만들기, 친절하게 분석하고 답변을 받아 앞으로 더 나은 응답 및 답변을 얻으십시오. –

답변

0

는 플러그인의 기본 설정 될 것입니다이

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

이 같은 플러그인에 설정을 추가합니다.

당신은 그래서 업데이트 된 코드는 것이다 사용자에게 우선 순위를 제공하는 단일 개체로 주어진 옵션

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

을 사용자 지정 옵션의 특성과 $ .fn.scrollAnimation.settings을 병합 $ .extend을 사용할 수 있습니다 be like

(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); 
관련 문제