0

我的页面中有一个 jQuery 画廊,我想让它在所有分辨率和屏幕上都是全宽的。

这页纸

jQuery:

$('#grid1').dynamicGallery({
                    src : 'gallery.xml',
                    height : 400,
                    width : 1350,
                    cols : 5,
                    min_rows : 1,
                    max_rows : 2,
                    random_heights : false,
                    padding: 1,
                    interval : 2000,
                    speed : 1000,
                    easing : 'easeOutQuad',
                    scale_images : true,
                    center_images : true,
                    click_action : 'lightbox',
                    show_title_in_lightbox : true
                });
  • 如您所见,我尝试给它更大的宽度,但它会移到页面的右侧,当使用 css 将 div 居中时,它在其他屏幕上的显示仍然不同。
4

1 回答 1

2

更新:

两个问题。

  1. 我从来没有定义viewportwidthviewportheight。必须这样做。

  2. 你不需要一个函数。只需定义两个变量,然后将不带函数的代码放在<head>页面部分。然后,当然,删除<body onload="resize()">并放<body>

完毕。最终代码如下所示:

<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
    <meta charset="UTF-8" />

    <title>Dynamic Grid</title>

    <meta name="description" content="" />
    <meta name="keywords" value="" />

    <link rel="stylesheet" href="http://www.tranceil.co.il/comp/css/layout.css" type="text/css" />
    <link rel="stylesheet" href="http://www.tranceil.co.il/comp/css/dynamic.grid.css" type="text/css" />
    <style>
        .shell > div {
            margin: 0px;
        }
    </style>
</head>
<body>
    <div class="shell" style="width: 100%; margin: 0 auto;">
        <div id="grid1"></div>
    </div>

    <script src="http://www.tranceil.co.il/comp/js/jquery.min.js"></script>
    <script src="http://www.tranceil.co.il/comp/js/dynamic.grid.gallery.js"></script>



    <script>
        var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

        (function($, undefined) {
            $(document).ready(function() {

                $('#grid1').dynamicGallery({
                    src : 'http://www.tranceil.co.il/comp/gallery.xml',
                    height : viewportheight,
                    width : viewportwidth,
                    cols : 5,
                    min_rows : 1,
                    max_rows : 2,
                    random_heights : false,
                    padding: 1,
                    interval : 2000,
                    speed : 1000,
                    easing : 'easeOutQuad',
                    scale_images : true,
                    center_images : true,
                    click_action : 'lightbox',
                    show_title_in_lightbox : true
                });

                $('#grid2').dynamicGallery({
                    src : 'http://www.tranceil.co.il/comp/gallery.xml',
                    height : 400,
                    width : 1350,
                    cols : 5,
                    min_rows : 1,
                    max_rows : 4,
                    random_heights : false,


            padding: 1,
                interval : 2000,
                speed : 1000,
                easing : 'easeOutQuad',
                scale_images : true,
                center_images : true,
                click_action : 'lightbox',
                show_title_in_lightbox : true
            });


        });
    })(jQuery);
</script>

原帖:

尚未针对您的情况专门测试此代码,但我认为它应该可以工作。

function resize() {
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

}

该函数将获取浏览器的高度和宽度。将您的<body>标签替换为

<body onload="resize()">

然后,对于您的画廊:

$('#grid1').dynamicGallery({
                    src : 'gallery.xml',
                    height : viewportheight,
                    width : viewportwidth,
                    cols : 5,
                    min_rows : 1,
                    max_rows : 2,
                    random_heights : false,
                    padding: 1,
                    interval : 2000,
                    speed : 1000,
                    easing : 'easeOutQuad',
                    scale_images : true,
                    center_images : true,
                    click_action : 'lightbox',
                    show_title_in_lightbox : true
                });

这应该将画廊的高度和宽度设置为与视口相同,从而填充 100% 的屏幕。

测试一下,如果你有问题,请告诉我。

于 2013-01-21T17:12:49.540 回答