Javascript 在窗口上调整图像大小调整大小
我正在构建图片查看器,但我的代码有问题:Javascript 在窗口上调整图像大小调整大小,javascript,jquery,resize,Javascript,Jquery,Resize,我正在构建图片查看器,但我的代码有问题: $('.table_content_results table').click(function() { $('#overlay').show(); $('#pdfFrame').show(); $(window).resize(); }); $(window).resize(function() { var contentWidth = $('#pdfFrame').children('img').width(
$('.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%。我的问题是如何防止这种情况一再发生
它只需在第一次显示图像时进行裁剪
我希望有人能帮助我
提前谢谢 从现在起,它将随着窗口大小的改变而改变。您可能想要的是,如果窗口达到一定的大小,则可以裁剪图像。所以你需要检查窗口的大小
$(window).resize(function()
{
if($(window).width() < 400 || $(window).height() < 400)
{
//execute crop
}
}
$(窗口)。调整大小(函数()
{
如果($(窗口).width()<400 | |$(窗口).height()<400)
{
//收割
}
}
您是否希望在窗口达到一定大小后裁剪图像,因为现在它将根据窗口的任何更改调整大小如果它只在加载时调整大小,而不是在调整大小时调整大小,请使用jQuery的load()not resize()命令?是的,但pdfFrame需要有一个窗口的位置中心,这取决于图像的大小。@LeonvanderVeen你也说是谁???然后你必须等待图像加载,而不是窗口加载!