2012-02-28 184 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 
    } 
}