1

我正在尝试创建一个可扩展的站点,在这个示例中说明了基本逻辑:

http://pastehtml.com/view/1eg2pr1.html

每当您调整浏览器窗口的大小时,中间的紫色框的数量都会发生变化。

但是有没有办法让顶部的绿色“徽标”框跟随这些框的宽度,如图所示:http: //imageshack.us/photo/my-images/198/testimg.jpg/

因此,如果第一行有 7 个可见的紫色框,则绿色框的宽度应与 theese 相同 - 如果第一行有 10 个可见,则为 10 个框的宽度

是否有可能做到这一点,也许使用 jquery?我知道我可以在绿色框上使用“宽度:100&”,但这并不遵循紫色框的确切宽度:/

4

1 回答 1

0

这是一个应该做你想做的脚本:

function adaptTitleWidth() {
    // reset default style
    $(".box").css("background","purple");
    // get the first row of boxes (the first box and the boxes having the same offset().top
    firstRowBoxes = $(".box").filter(function() {
        return $(this).offset().top === $(".box:first").offset().top;
        // changes the first row of boxes background to blue
    }).css("background","blue");
    // changing .logo.width() : number of boxes on the first row * outer width of the boxes, margin included - the last margin-right
    $(".logo").width(firstRowBoxes.length * $(".box:first").outerWidth(true) - parseInt($(".box:first").css("margin-right")));
}

$(function() {
    adaptTitleWidth();
    window.onresize = function(event) {
        adaptTitleWidth();
    }
});


jsBin 示例在这里

于 2011-05-10T13:12:13.340 回答