【发布时间】:2014-09-10 16:39:19
【问题描述】:
我在我的图片库中应用了 jquery lighbox,但由于图片的大小可变,灯箱大小不固定,因此打开图片的原始大小,这反过来又导致 biga 图像走出屏幕并显示浏览器中的水平滚动条。
因此我正在寻找将固定宽度和高度应用于灯箱的方法,以便每个图像都必须在灯箱中以这种尺寸显示。
请帮忙..
更新
我刚刚尝试了 Scott (http://geekswithblogs.net/wojan/archive/2009/06/17/jquerylightbox.aspx) 给我的解决方案,我做到了,
function _resize_container_image_box(intImageWidth,intImageHeight) {
// Get current width and height
//rescale if necessary
if((settings.maxWidth != null && settings.maxHeight != null) && (intImageWidth > settings.maxWidth || intImageHeight > settings.maxHeight)){
var isWider = intImageWidth > intImageHeight;//is the image wide or tall?
var scale = isWider ? settings.maxWidth/intImageWidth : settings.maxHeight/intImageHeight;
intImageWidth = intImageWidth * scale;
intImageHeight = intImageHeight * scale;
}
$('#lightbox-image').height(intImageHeight);
$('#lightbox-image').width(intImageWidth);
var intCurrentWidth = $('#lightbox-container-image-box').width();
var intCurrentHeight = $('#lightbox-container-image-box').height();
// Get the width and height of the selected image plus the padding
var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image´s width and the left and right padding value
var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image´s height and the left and right padding value
// Diferences
var intDiffW = intCurrentWidth - intWidth;
var intDiffH = intCurrentHeight - intHeight;
// Perfomance the effect
$('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
if ( $.browser.msie ) {
___pause(250);
} else {
___pause(100);
}
}
$('#lightbox-container-image-data-box').css({ width: intImageWidth });
$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
};
与
$('#gallery a').lightBox( maxHeight: null,
maxWidth: null);
});
但是每当我这样做并单击图像时,就会在浏览器的另一个选项卡中打开,所有的灯箱功能都会失败
请帮我改正
谢谢
【问题讨论】:
标签: javascript jquery css lightbox