/**
 * helper class to move all elements which are positioned fixed or absolute to the window
 * down by a offset so that a fixed toolbar may be displayed on top.
 * 
 * Usage:
 *  var ff = new FixedFix();
 *  ff.setTop(30); $("html").css("marginTop", "30px");
 **/
function FixedFix() {
    var self = this;
    self.els = null;
    self.init = function() {
        self.els = $('*').filter(function(){
            var position = $(this).css('position');
            if (((position === 'fixed') || (position === 'absolute')) && $(this).closest('.wt-dont-fix-fixed').length == 0) {
                if (position === 'fixed') return true;
                return ! ($(this).parents().is(function(index) {
                    var p = $(this).css('position'); return (p==='absolute' || p==='relative');
                }));
            } else {
                return false;
            }
        }).each(function() { $(this).data('origTop', $(this).css('top')) });
    }
    self.setTop = function(top) {
         self.els.each(function() { $(this).css('top', parseInt($(this).data('origTop'))+top+'px') });
    };
    self.init();
}

Kommentare