2011-09-20 103 views

回答

1

如果您向resize添加處理程序,您將能夠從$(this).height()$(this).width()的處理程序內檢查元素的大小。這樣,如果數字不符合某些特徵,您可以返回而不做任何事情。

檢測尺寸的增加應該記住「最後一個」值,並將其與目前那些在處理程序中進行比較,例如可以:

$(「#ID」)調整(函數(){。 變種高度= $(本).height(); VAR寬度= $(本).WIDTH();

var heightIncreased = height > lastHeight; 
var widthIncreased = width > lastWidth; 
var heightDecreased = height < lastHeight; 
var widthDecreased = width < lastWidth; 

if(heightIncreased || widthIncreased) { 
    // whatever 
} 

lastHeight = height; 
lastWidth = width; 

});

但是,請注意:沒有保證,以多少倍的大小調整處理器將元素的過程中,被稱爲被調整(例如,你可能會在年底連續或只有一次triggerred),因爲這取決於瀏覽器。