Hi,
I am learning to turn a function into a plugin. and turning a function into a plugin seems quite straight forward. But what if I have two functions correspond with each other - how can I turn these two functions into one plugin then?
such as I have these functions for making a jquery slideshow,
function run_slide(target_slide) {
//add a class the the first element
$('li:first-child',target_slide).addClass('active');
//Set the opacity of all images to 0
$('.slide li').css({opacity: 0.0});
//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
setInterval('loop_slide("'+target_slide+'")',5000);
}
function loop_slide(target_slide) {
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.slide li:first-child') :current.next()) : $('.slide li:first-child'));
//Set the fade in effect for the next image, show class has higher z-index
current.addClass('last-active');
next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function(){
current.animate({opacity: 0.0}, 1000).removeClass('active last-active');
$('.caption p',target_slide).html(caption_description);
});
}
this is how I call these functions,
run_slide('#slide');
ideally I would like to call these functions from the plugin method,
$('#slide').run_slide();
but how to wrap these two functions into the plugin making method below as in jquery’s documenation,
(function( $ ){
$.fn.myPlugin = function() {
// Do your awesome plugin stuff here
};
})( jQuery );
Hope to hear from you soon.
Many thanks,
Lau