0

I'm busy building a javascript class to automate the creation of Jquery UI Sliders.

    CustomSlider.prototype.initialize = function(slider_id, min_id, max_id, step, min, max){
        this.$slider = $('#' + slider_id);
        this.$min = $('#' + min_id);
        this.$max = $('#' + max_id);
        this.min = min;
        this.max = max;
        this.step = step;

        this.$slider.slider({
            range: true,
            step: this.step,
            min: this.min,
            max: this.max,
            values: [(this.min + (step * 4)), (this.max - (step * 4))],
            slide: this.slide(event, ui)
        });

        this.$min.text(this.min + (step * 4));
        this.$max.text(this.max - (step * 4));
    };

    CustomSlider.prototype.slide = function(event, ui){
        this.$min.text(ui.values[0]);
        this.$max.text(ui.values[1]);
    };

When I try to bind the slide event it won't take the "event" and "ui" variables. How can I bind this event to my own function?

1 Answer 1

3

It should be just

    this.$slider.slider({
        range: true,
        step: this.step,
        min: this.min,
        max: this.max,
        values: [(this.min + (step * 4)), (this.max - (step * 4))],
        slide: this.slide
    });

You need to assign the function reference as the value for slide property.

In your case you are calling the this.slide function as assigns the value returned by it to the slide property, in this case undefined

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.