I tried to do something like you have mentioned above and ended up checking other links.
It seems like for plugin we need to define specific function first for best practise.If we trying to prototyping that function like
myplugin.prototype.newfn = function (){
}
Then we need execute the myplugin function first.
All the details required for the best practise is in following answer :
How to create a jQuery plugin with methods?
Here is the link for useful boilerpalates of plugin :
Boilerplates for plugin
and ofcourse jsfiddle for your working plugin :
var methods = {
slideIn:function(){
this.fadeIn().slideDown();
return this;
},
slideOut:function(){
this.fadeOut().slideUp();
return this;
},
init: function() {
// or you can do more functions here
return this;
}
};
$.fn.slides = function(methodOrOptions) {
if ( methods[methodOrOptions] ) {
return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
// Default to "init"
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.slides' );
}
};
And you can call it like this :
$('h1').click(function(){
$(this).slides("slideOut");
});
slide up slide down jsfiddle