Я учусь превращать функцию в плагин.и превращение функции в плагин кажется довольно простым.Но что, если у меня две функции соответствуют друг другу - как я могу затем превратить эти две функции в один плагин?
, например, у меня есть эти функции для создания слайд-шоу jquery,
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);
});
}
это то, как я называю эти функции,
run_slide('#slide');
в идеале я хотел бы вызвать эти функции из метода плагина,
$('#slide').run_slide();
, но как обернуть эти две функции в плагинописанный ниже метод, как в документации jquery ,
(function( $ ){
$.fn.myPlugin = function() {
// Do your awesome plugin stuff here
};
})( jQuery );
спасибо.