1

I started trying to create my own plugin using jQuery and the prototype function. My code looks like the following:

var Slider = function(element, controls, interval) {
    this.element = element;
    this.controls = controls;
    this.interval = interval || 5000;

    this.init();
};

Slider.prototype = {
    init: function() {
        if (this.controls)
            this.setControls();

        this.element.hide();
        this.slides[0].show();
        this.fadeIt();
    }
}

And inside prototype are more functions. Currently I'm creating a slider by calling the following:

new Slider($(".slide"), $(".slider").find(".controls").find("i"), 6000);

But how I want to do is is something like this:

Slider.init({
   element: $(".slide"),
   controls: $(".slider").find(".controls").find("i"),
   interval: 6000,
});

I tried searching for a solutions but I only could find how to make something like this:

$(".slider").Slider();

Anyone who can help me out or knows what to search for? Thanks instead!

1 Answer 1

1

I was looking up "jQuery Plugin init" when I found your question. I also found this great article with a jQuery Plugin boilerplate that include an init() function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.