Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery中的全宽度库_Javascript_Jquery_Css - Fatal编程技术网

Javascript jQuery中的全宽度库

Javascript jQuery中的全宽度库,javascript,jquery,css,Javascript,Jquery,Css,我的页面中有一个jQuery库,我想让它与所有分辨率和屏幕保持全宽 jQuery: $('#grid1').dynamicGallery({ src : 'gallery.xml', height : 400, width : 1350, cols : 5, min_rows : 1,

我的页面中有一个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居中时,它仍然显示 在其他屏幕上则不同

更新:

两个问题

  • 我从未定义过
    viewportwidth
    viewportheight
    。我必须这么做

  • 你不需要函数。只需定义这两个变量,并将不带函数的代码放在页面的
    部分。然后,当然,删除
    ,只需放入

  • 完成了。最后的代码如下所示:

    <!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>
    
    此函数将获取浏览器的高度和宽度。将
    标记替换为

    <body onload="resize()">
    
    这应该将库的高度和宽度设置为与视口相同,从而填充100%的屏幕


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

    .shell
    的宽度为800px,边距为:0自动;让那100%Hey buddy,thanx用于代码..我得到了未捕获的引用错误:viewportheight未定义..我猜我没有把它放在正确的位置?我正在查看您的源代码,看起来您将函数放在了正确的位置…尝试在
    $(文档)中放置警报.ready
    函数,查看是否正在获取
    视口高度
    视口宽度
    的值。我正在查看源代码,将尝试设计解决方案。明白了!更新了我的答案:)很高兴我能帮忙!这对我来说也是一次学习经历
    <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
                    });