2012-02-28 139 views
1

我建立一個圖片瀏覽器和我的問題,我的代碼:調整圖像大小調整

$('.table_content_results table').click(function() 
{ 
    $('#overlay').show(); 
    $('#pdfFrame').show(); 
    $(window).resize(); 
}); 

$(window).resize(function() 
{ 

    var contentWidth = $('#pdfFrame').children('img').width(); 
    var contentHeight = $('#pdfFrame').children('img').height(); 

    var imageWidth = contentWidth/2; 
    var imageHeight = contentHeight/2; 

    $('#pdfFrame').children('img').width(imageWidth).height(imageHeight); 

    $('#pdfFrame').css(
    { 
     position:'absolute', 
     left: ($(window).width() - imageWidth)/2, 
     top: ($(window).height() - imageHeight)/2 
    }); 
}); 

隨着劇本我農作物在div #pdfFrame圖像的大小。一個問題是,我每次調整窗口大小時,圖像作物都會變成50%。我的問題是如何防止這種反覆耕作。

它只需要通過第一次顯示圖像進行裁剪。

我希望有人能幫助我。

在此先感謝!

+0

是你想要的圖像裁剪窗口達到一定的規模,因爲現在它要調整窗口 – Henesnarfel 2012-02-28 14:14:29

+0

的任何變化。如果我們假設對負載調整而已,不調整,使用jQuery的負載後()不調整()? – adeneo 2012-02-28 14:15:39

+0

是的,但pdfFrame需要有一個窗口的位置中心,這取決於圖像的大小。 – 2012-02-28 14:18:45

回答

2

截至目前它將改變任何窗口的大小。你可能想要的是,如果窗口達到一定大小的圖像裁剪。所以你需要檢查窗口大小。

$(window).resize(function() 
{ 
    if($(window).width() < 400 || $(window).height() < 400) 
    { 
     //execute crop 
    } 
}