题
我知道我可以使用帧宽度和框架光选项来控制内联和iframe内容的帧大小,但是在显示图像时,我该怎么办?
我的问题是,我想在一个非常水平且垂直方面不多的花式盒中显示的图像。 Fancybox将其缩放,因此Lightbox确实很宽,不是很高,这意味着您根本看不到图像。
我想要的是将图像水平滚动在Lightbox中。 (不,我无法更改图像)。
有什么想法吗?
解决方案
我最终只是黑客式的花式盒,并添加了另一个选择来完成我想要的事情。这是要点:
if (opts.imgManSize) {
_set_content('<img alt="" id="fancy_img" src="'+imagePreloader.src+'" />',opts.imgWidth,imagePreloader.height+20);
} else {
_set_content('<img alt="" id="fancy_img" src="'+imagePreloader.src+'" />',width,height);
}
...
if (opts.imgManSize) {
$("#fancy_content").css('overflow','auto');
}
...
if (opts.imgManSize) {
$('#fancy_img').css('width','auto');
}
...
$.fn.fancybox.defaults = {
...
imgManSize:false,
imgWidth:425,
imgHeight:355,
...
}
奇迹般有效。
其他提示
您可以通过修改CSS来使框架大小根据图像的大小进行调整。
要覆盖插件创建的宽度和高度声明,请添加:
#fancybox-inner {
width: auto!important;
height: auto!important;
}
#fancybox-wrap{
width: auto!important;
height: auto!important;
}
并删除 position:absolute
上 #fancybox-inner
我本人遇到了这个问题,并编写了一些代码来解决此问题,以根据我发现的现有片段嵌入新的Vimeo iframe'D视频。这将允许您按花式盒子的基础上的宽度和高度添加URL参数。如果您不添加它们,默认值将打开一个高度为90%和90%的iFrame。
(function($){
$(function(){
// Fancybox: IFRAME
var fancybox_iframe = $('.fancybox-iframe');
if (fancybox_iframe.length > 0){
fancybox_iframe.each(function(index){
// Inline frame width param
if( $(this).attr('href').match(/width=[0-9]+/i) ){
var fWidth = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));
} else {
var fWidth = '90%';
}
// Inline frame height param
if( $(this).attr('href').match(/height=[0-9]+/i) ){
var fHeight = parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
} else {
var fHeight = '90%';
}
if(window.console&&window.console.log) {
console.log('fWidth #'+index+': '+fWidth);
console.log('fHeight #'+index+': '+fHeight);
}
$(this).fancybox({
'titlePosition' : 'inside',
'type' : 'iframe',
'autoScale' : true,
'padding' : '10',
'width' : fWidth,
'height' : fHeight,
'centerOnScroll' : true
});
});
}
});
})(jQuery);
要使用此功能,您将使用以下内容:
<a href="http://player.vimeo.com/video/16429685?color=ffffff&width=800&height=450" class="fancybox-iframe" title="Citizen Schools 101">Inline Vimeo Video</a>
希望这对某人有帮助!
如果您使用的是AJAX负载,将图像包裹在DIV中(如果是在线)或页面中。然后,将DIV上的样式设置为IFRAM的宽度,并将溢出CSS属性设置为溢出:滚动;
不隶属于 StackOverflow