MajAfy
MajAfy

Reputation: 3097

change the defaults from outside of plugin

My plugin is :

$.fn.iPopup = function() {
    var opts = new function() {
        this.width = 957;
        this.height = 590;
        this.left = ($(document).width() / 2) - (this.width/2) - (17/2);
        this.top = 160; 
    }
    alert (opts.width);
}

I want change the width or height when I call plugin , like:

$('div#tP').iPopup({width:280});

what should I do in my plugin?

Upvotes: 1

Views: 61

Answers (1)

The Alpha
The Alpha

Reputation: 146269

$.fn.iPopup = function(options) {
    var defaults = {
        'width' : 957,
        'height' : 590,
        'left' : ($(document).width() / 2) - (this.width()/2) - (17/2),
        'top' : 160
    },
    opts=$.extend({}, defaults, options);
}

Call it

$('div#tP').iPopup({width:280});

An example.

Upvotes: 1

Related Questions