這裏是一個腳本,應該做你想要什麼:
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 example here
輝煌,感謝..這是一個相當不錯的腳本;) – donpedroper 2011-05-10 14:28:19
高興你喜歡它;) – Sylvain 2011-05-10 14:30:04