2

http://jsfiddle.net/suenot/3b3XM/1/

// in FF and IE each() don't work offset()
// $(this).offset().top return empty string
$(document).ready(function(){
    var index = 0;
    $('.box').each(function(){
        var background = $(this).css('background');
        $(this).css('background', 'none');
        var height = $(this).css('height');
        var top = $(this).offset().top;
        $('body').prepend('<div id="box' + ++index + '"></div>');
        $('#box' + index).css({
            'height': height,
            'background': background,
            'position': 'absolute',
            'z-index': '-1',
            'top': top,
            'width': '100%'
        });
    });
});​

助けてください、解決策が見つかりません。

4

1 に答える 1

2

何が欲しいかわかりませ$(this).css('background-color');んが、更新するとボックスが表示されます。フィドルの出力を参照してください

$(document).ready(function(){
    var index = 0;
    $('.box').each(function(){
        var background = $(this).css('background-color');
        $(this).css('background', 'none');
        var height = $(this).css('height');
        var top = $(this).offset().top;
        $('body').prepend('<div id="box' + ++index + '"></div>');
        $('#box' + index).css({
            'height': height,
            'background': background,
            'position': 'absolute',
            'z-index': '-1',
            'top': top,
            'width': '100%'
        });
    });
});
于 2012-05-10T18:00:32.787 に答える