将 slimbox(灯箱)图像限制为窗口大小

发布于 2024-09-10 00:11:37 字数 285 浏览 5 评论 0原文

大家好,

有人知道如何将 slimbox 的覆盖窗口大小限制为用户窗口大小的百分比(就像 Prettyphoto 那样)

谢谢

,这是模块代码: http://paste.ly/3Kz

和 slimbox js: http://paste.ly/3L0

HI all,

Anyone know how to limit the overlay window size of slimbox to be a percentage of the user's window size (like prettyphoto does)

Thanks

Here's the module code:
http://paste.ly/3Kz

And the slimbox js:
http://paste.ly/3L0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

晨曦÷微暖 2024-09-17 00:11:37

实际上,你的解决方案都没有完全适合我,所以我必须将它们放入搅拌机中,并通过这样做来混合结果:

正如他所说,在 slimbox2.js 中查找这一行

w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});
w(p).width(k.width);
w([p,I,d]).height(k.height);

并将其替换为以下块:

        var winWidth  = window.innerWidth  - 20;
        var winHeight = window.innerHeight - 120;
        if (winWidth > winHeight) { 
            var maxSize = winHeight; 
        } else { 
            var maxSize = winWidth;
        }

        /* determine proper w and h for img, based on original image'w dimensions and maxSize */
        var my_w = k.width; 
        var my_h = k.height;            

        if (my_w > my_h) {
            my_h = maxSize * my_h / my_w;
            my_w = maxSize;
        } else {
            my_w = maxSize * my_w / my_h;
            my_h = maxSize;
        }

        if (k.width > my_w || k.height > my_h){ /* constrain it */
            w(g).css({backgroundImage:"url("+n+")",backgroundSize:""+my_w+"px "+my_h+"px",visibility:"hidden",display:""});
            w(p).width(my_w);
            w([p,I,d]).height(my_h);    
        }
        else { /* default behaviour  NORMAL before hackeing*/
            w(g).css({backgroundImage:"url("+n+")",backgroundSize:"",visibility:"hidden",display:""});
            w(p).width(k.width);
            w([p,I,d]).height(k.height);            
        }       

*友善一点,我是早期阶段的业余开发者;)

Actually neither of your solutions quite did it for me , so i had to put them in a blender and sorta mix the result by doing this:

as he said, look out for this lines in slimbox2.js

w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});
w(p).width(k.width);
w([p,I,d]).height(k.height);

and replace them with this block:

        var winWidth  = window.innerWidth  - 20;
        var winHeight = window.innerHeight - 120;
        if (winWidth > winHeight) { 
            var maxSize = winHeight; 
        } else { 
            var maxSize = winWidth;
        }

        /* determine proper w and h for img, based on original image'w dimensions and maxSize */
        var my_w = k.width; 
        var my_h = k.height;            

        if (my_w > my_h) {
            my_h = maxSize * my_h / my_w;
            my_w = maxSize;
        } else {
            my_w = maxSize * my_w / my_h;
            my_h = maxSize;
        }

        if (k.width > my_w || k.height > my_h){ /* constrain it */
            w(g).css({backgroundImage:"url("+n+")",backgroundSize:""+my_w+"px "+my_h+"px",visibility:"hidden",display:""});
            w(p).width(my_w);
            w([p,I,d]).height(my_h);    
        }
        else { /* default behaviour  NORMAL before hackeing*/
            w(g).css({backgroundImage:"url("+n+")",backgroundSize:"",visibility:"hidden",display:""});
            w(p).width(k.width);
            w([p,I,d]).height(k.height);            
        }       

*be kind, i'm an amateur developer on early stage ;)

我喜欢麦丽素 2024-09-17 00:11:37

我试图使用 Redscouse 的解决方案,但我认为他使用的是旧版本的 slimbox。这是一个基于 v2.04 的解决方案,它将限制图像以适合当前浏览器窗口。

找到 animateBox() 函数。在顶部附近,您应该找到如下所示的线条:

$(image).css({backgroundImage: "url(" + activeURL + ")", visibility: "hidden", display: ""});
$(sizer).width(preload.width);
$([sizer, prevLink, nextLink]).height(preload.height);

将这些线条替换为以下线条:

/* make sure the image won't be bigger than the window */
var winWidth = $(window).width() - 20;
var winHeight = $(window).height() - 104;
var maxSize = (winWidth > winHeight) ? winHeight : winWidth; /* the smaller dimension determines max size */

/* determine proper w and h for img, based on original image'w dimensions and maxSize */
var my_w = preload.width; 
var my_h = preload.height;
if (my_w > my_h)
{
    my_h = maxSize * my_h / my_w;
    my_w = maxSize;
}
else
{
    my_w = maxSize * my_w / my_h;
    my_h = maxSize;
}

if (preload.width > my_w || preload.height > my_h){ /* constrain it */
    $(image).css({backgroundImage: "url(" + activeURL + ")", backgroundSize: my_w + "px " + my_h + "px", visibility: "hidden", display: ""});
    $(sizer).width(my_w);
    $([sizer, prevLink, nextLink]).height(my_h);
}
else { /* default behaviour */
    $(image).css({backgroundImage: "url(" + activeURL + ")", backgroundSize: "", visibility: "hidden", display: ""});
    $(sizer).width(preload.width);
    $([sizer, prevLink, nextLink]).height(preload.height);
}

-20 和 -104 调整是为了考虑 slimbox 在图像周围使用的额外空间。请随意根据需要调整它们。

I was trying to use Redscouse's solution but I think his used an older version of slimbox. Here is a solution based on v2.04 that will constrain the image to fit inside the current browser window.

Locate the animateBox() function. Near the top you should find lines that look like this:

$(image).css({backgroundImage: "url(" + activeURL + ")", visibility: "hidden", display: ""});
$(sizer).width(preload.width);
$([sizer, prevLink, nextLink]).height(preload.height);

Replace those lines with these:

/* make sure the image won't be bigger than the window */
var winWidth = $(window).width() - 20;
var winHeight = $(window).height() - 104;
var maxSize = (winWidth > winHeight) ? winHeight : winWidth; /* the smaller dimension determines max size */

/* determine proper w and h for img, based on original image'w dimensions and maxSize */
var my_w = preload.width; 
var my_h = preload.height;
if (my_w > my_h)
{
    my_h = maxSize * my_h / my_w;
    my_w = maxSize;
}
else
{
    my_w = maxSize * my_w / my_h;
    my_h = maxSize;
}

if (preload.width > my_w || preload.height > my_h){ /* constrain it */
    $(image).css({backgroundImage: "url(" + activeURL + ")", backgroundSize: my_w + "px " + my_h + "px", visibility: "hidden", display: ""});
    $(sizer).width(my_w);
    $([sizer, prevLink, nextLink]).height(my_h);
}
else { /* default behaviour */
    $(image).css({backgroundImage: "url(" + activeURL + ")", backgroundSize: "", visibility: "hidden", display: ""});
    $(sizer).width(preload.width);
    $([sizer, prevLink, nextLink]).height(preload.height);
}

The -20 and -104 adjustments are to take into account extra space that slimbox uses around the image. Feel free to tweak those as needed.

一抹苦笑 2024-09-17 00:11:37

我遇到了类似的问题,图像扩展超出了窗口的大小。我知道我可以通过限制上传图像的大小来解决这个问题,但我不想这样做,我宁愿能够设置 slimbox 窗口的大小,所以我设置了任务,这就是我来的和它一起工作完美! :)

为了将来更容易调整,您需要将 userDefinedWidth 和 userDefinedHeight 行添加到选项中对 slimbox 的调用中:

示例:

$(function($) {
    $("a[rel^='lightbox']").slimbox({
    /* Put custom options here */
    userDefinedWidth:640, /* set max width here */
    userDefinedHeight:480, /* set max height here */
    initialWidth: 250,
    initialHeight: 250,
    imageFadeDuration: 400
});

接下来,打开 slimbox.js (或 slimbox2.js)并再次查找选项,这次添加没有值的 userDefinedWidth 和 userDefinedHeight,如下所示:

w.slimbox=function(O,N,M){
    u=w.extend({
    userDefinedWidth:'',
    userDefinedHeight:'',
    loop:false,
    ...etc.
    ...etc.

接下来找到名为 i 的函数。
在 i 函数中,将以下行: 替换

w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});
w(p).width(k.width); 
w([p,I,d]).height(k.height); 

为以下行:

var my_w = u.userDefinedWidth; 
var my_h = u.userDefinedHeight;
w(g).css({backgroundImage:"url("+n+")",backgroundSize:""+my_w+"px "+my_h+"px",visibility:"hidden",display:""});
w(p).width(my_w);
w([p,I,d]).height(my_h);

完成此操作后,您就可以开始操作了,并且应该能够将 slimbox 的大小调整为您选择的设置。

皮特.

PS:我是一个正在掌握 jquery/javascript 的 php 人员,所以如果有人可以做得更好/更快/更容易,请随意。哦,请随意在任何您喜欢的地方使用此代码。 ;)

I had a similar problem where the image was expanding beyond the size of the window. I know I could of solved this by restricting the size of the image on upload, but I didn't want to do that, I would rather be able to set the size of slimbox window so I set about the task, here's what I came up with and it works perfectly! :)

To make it easier to adjust in the future you want to add the userDefinedWidth and userDefinedHeight lines to your call to slimbox in the options:

Example:

$(function($) {
    $("a[rel^='lightbox']").slimbox({
    /* Put custom options here */
    userDefinedWidth:640, /* set max width here */
    userDefinedHeight:480, /* set max height here */
    initialWidth: 250,
    initialHeight: 250,
    imageFadeDuration: 400
});

Next, Open slimbox.js (or slimbox2.js) and look for the options again, this time add the userDefinedWidth and userDefinedHeight with no values like so:

w.slimbox=function(O,N,M){
    u=w.extend({
    userDefinedWidth:'',
    userDefinedHeight:'',
    loop:false,
    ...etc.
    ...etc.

Next find the function called i.
In the i function replace the following lines:

w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});
w(p).width(k.width); 
w([p,I,d]).height(k.height); 

with these lines:

var my_w = u.userDefinedWidth; 
var my_h = u.userDefinedHeight;
w(g).css({backgroundImage:"url("+n+")",backgroundSize:""+my_w+"px "+my_h+"px",visibility:"hidden",display:""});
w(p).width(my_w);
w([p,I,d]).height(my_h);

Once you have done that, you're good to go and should be able to resize the slimbox to a setting of your choice.

Pete.

PS: I'm a php guy getting to grips with jquery/javascript so if anyone can make this better/quicker/easier please feel free. Oh, and please feel free to use this code anywhere you like. ;)

隐诗 2024-09-17 00:11:37

虽然 Avinash 的响应有效,但它要简单得多:

.pp_overlay {max-width:100%; max-height:100%;}

上述字段中的百分比将其视为用户浏览器大小的百分比。

.pp_overlay 类是 PrettyPhoto 中的名称。您需要找到 slimbox 的等效项。

While Avinash's response works, this is much more simple:

.pp_overlay {max-width:100%; max-height:100%;}

The percent in the above fields takes it as a percent of the user's browser size.

The class .pp_overlay is what it is called in PrettyPhoto. You will need to find the equivalent for slimbox.

听风吹 2024-09-17 00:11:37

捕获用户窗口分辨率并根据捕获的信息设置覆盖层的宽度和高度...

$('#overlay').width($(window).width()).height($(window).height());

capture the users window resolution and set the overlay's width and height according to captured info...

$('#overlay').width($(window).width()).height($(window).height());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文