javascript - jquery plugin error -


i'm trying make plugin (from other code have), can't options part work d:

plugin (so far):

(function($){     $.fn.scbox = function(options){         var $opts = $.extend($.fn.scbox.defaults, options);          $.fn.scbox.defaults = {             start: 40,             //i: fn.scbox.defaults.start,             width: 200,             height: 50,             min: 0,             step: 10,             fontsize: 15,             textcolor: "#fff",             bgcolor: "#000",             slidecolor: "#ff0000"         }          console.log($.fn.scbox.defaults);     } })(jquery); 

when try call $.scbox();, error: uncaught typeerror: object function (a,b){return new e.fn.init(a,b,h)} has no method 'scbox' want log options gave d:

jquery plugins called on jquery objects. aren't supposed call them directly. you're supposed call on jquery object.

$('#myelement').scbox(); 

also, you're calling $.extend on $.fn.scbox.defaults before declare it.

    $.fn.scbox.defaults = {         start: 40,         //i: fn.scbox.defaults.start,         width: 200,         height: 50,         min: 0,         step: 10,         fontsize: 15,         textcolor: "#fff",         bgcolor: "#000",         slidecolor: "#ff0000"     }      var $opts = $.extend($.fn.scbox.defaults, options); 

note: $.extend modifies object passed 1st parameter (it returns it). so, don't need var $opts =:

$.extend($.fn.scbox.defaults, options); console.log($.fn.scbox.defaults); 

or, can do:

var $opts = $.extend({}, $.fn.scbox.defaults, options); console.log($opts); 

demo: http://jsfiddle.net/nfdth/


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -