Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Как вызвать через window.onresize функцию внутри prototype (https://javascript.ru/forum/misc/2738-kak-vyzvat-cherez-window-onresize-funkciyu-vnutri-prototype.html)

hwtech 05.02.2009 12:59

Как вызвать через window.onresize функцию внутри prototype
 
Добрый день!

Ниже упрощёный вариант моего кода, который закрывает полупрозрачным DIV элементом весь BODY:

Код:


var Wait = function(){
        this._cover = $('cover_001');

        this.recalculate();
        window.onresize = this.recalculate;

        this.cover();
}
//----------------------------------------------------------------------------------------------------
Wait.prototype._cover;                                                                                        // Объект слоя
Wait.prototype.opacity                =        0.4;                                                        // Прозрачность слоя
//--------------------------------------------------------------
Wait.prototype.rushWidth        =        0;                                                                //
Wait.prototype.rushHeight        =        0;                                                                //
Wait.prototype.rushX                =        0;                                                                //
Wait.prototype.rushY                =        0;                                                                //
//----------------------------------------------------------------------------------------------------
Wait.prototype.cover = function(){                                                                // Накрыть
        this.recalculate();

        this._cover.style.width                        =        this.rushWidth+"px";
        this._cover.style.height                =        this.rushHeight+"px";
        this._cover.style.left                        =        this.rushX+"px";
        this._cover.style.top                        =        this.rushY+"px";
        this._cover.style.opacity                =        this.opacity;
        this._cover.style.filter                =        "alpha(opacity = "+(this.opacity*100)+")";
}

Wait.prototype.recalculate = function(){                                                // Пересчитать ширину, высоту, позицию и т.п.
        if(this.__object.parentNode===null){
                this.rushWidth                        =        this.getClientWidth();
                this.rushHeight                        =        document.height || (document.body.offsetHeight+30);
                this.rushX                                =        0;
                this.rushY                                =        0;
        }else{
                this.rushWidth                        =        this.__object.offsetWidth;
                this.rushHeight                        =        this.__object.offsetHeight;
                this.rushX                                =        this.findPos(this.__object)[0];
                this.rushY                                =        this.findPos(this.__object)[1];
        }
}

Хочу сделать, так чтобы при изменении окна все параметры (ширина, высота, положение XY) пересчитывались... Пересчёт как вы видите идёт в функции Wait.recalculate(), как мне её можно вызвать таким образом чтобы передать в неё как аргумент сам класс Wait, к котором требуется пересчёт? Или как сделать так чтобы функция вызывалась прямо внутри нового класса Wait...



Код который используется в HTML

Код:

        var screenFreeze_Object = new Wait();
        screenFreeze_Object.cover();


Kolyaj 05.02.2009 13:33

http://javascript.ru/tutorial/object/thiskeyword


Часовой пояс GMT +3, время: 02:05.