javascript - 将 PhotoSwipe 配置为不使用整个窗口?

标签 javascript jquery css jquery-mobile photoswipe

我目前正在尝试使用 PhotoSwipe 构建移动图片库. 我已经能够让它工作,但有一个小问题。当我 单击照片缩略图,实际照片始终占据整个 视口(viewport)。当您在移动设备上查看画廊时,这是可以的。 但是如果你的视口(viewport)是电脑屏幕而图像不是 高分辨率之一,照片可能非常模糊。我宁愿限制照片 在计算机上查看时宽度可能为 300 到 400 像素。有没有 一种在 PhotoSwipe 中执行此操作的方法?我阅读了文档但不能 完全弄明白了。我在下面附上了我的代码。

谢谢。

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>PhotoSwipe - jQuery Mobile Version</title>
    <link rel="stylesheet" href="lib/jquery.mobile-1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
    <link rel="stylesheet" href="lib/photoswipe/photoswipe.css" />
    <link rel="stylesheet" href="css/mediaqueries.css" />
    <style type="text/css">
        div.gallery-row:after {
            clear: both;
            content: ".";
            display: block;
            height: 0;
            visibility: hidden;
        }
        div.gallery-item {
            float: left;
            width: 33.333333%;
        }
        div.gallery-item a {
            display: block;
            margin: 5px;
            border: 1px solid #3c3c3c;
        }
        div.gallery-item img {
            display: block;
            width: 100%;
            height: auto;
        }
        #Gallery1 .ui-content, #Gallery2 .ui-content {
            overflow: hidden;
        }
    </style>
    <script type="text/javascript" src="lib/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="lib/jquery.mobile-1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
    <script type="text/javascript" src="lib/simple-inheritance.min.js"></script>
    <script type="text/javascript" src="lib/jquery.animate-enhanced.min.js"></script>
    <script type="text/javascript" src="lib/photoswipe/code-photoswipe-jQuery-1.0.11.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('div.gallery-page').live('pageshow', function(e) {
                // Re-initialize with photos for the current page
                $('div.gallery a', e.target).photoSwipe();
                return true;
            });
        });
    </script>
</head>
<body>
    <div data-role="page" id="Home">
        <div data-role="header">
            <h1>PhotoSwipe</h1>
        </div>
        <div data-role="content" >  
            <p>These examples show PhotoSwipe integrated with jQuery Mobile:</p>        
            <ul data-role="listview" data-inset="true">
                <li><a href="#Gallery1">First Gallery</a></li> 
                <li><a href="#Gallery2">Second Gallery</a></li> 
            </ul> 
        </div>
        <div data-role="footer">
            <h4>&copy; 2011 PhotoSwipe</h4>
        </div>
    </div>
    <div data-role="page" id="Gallery1" class="gallery-page">
        <div data-role="header">
            <h1>First Gallery</h1>
        </div>
        <div data-role="content">   
            <div class="gallery">
                <div class="gallery-row">
                    <div class="gallery-item"><a href="images/01.jpg" rel="external"><img src="images/01-thumb.jpg" alt="Image 1" /></a></div>
                    <div class="gallery-item"><a href="images/02.jpg" rel="external"><img src="images/02-thumb.jpg" alt="Image 2" /></a></div>
                    <div class="gallery-item"><a href="images/03.jpg" rel="external"><img src="images/03-thumb.jpg" alt="Image 3" /></a></div>
                </div>
                <div class="gallery-row">
                    <div class="gallery-item"><a href="images/04.jpg" rel="external"><img src="images/04-thumb.jpg" alt="Image 4" /></a></div>
                    <div class="gallery-item"><a href="images/05.jpg" rel="external"><img src="images/05-thumb.jpg" alt="Image 5" /></a></div>
                    <div class="gallery-item"><a href="images/06.jpg" rel="external"><img src="images/06-thumb.jpg" alt="Image 6" /></a></div>
                </div>
                <div class="gallery-row">
                    <div class="gallery-item"><a href="images/07.jpg" rel="external"><img src="images/07-thumb.jpg" alt="Image 7" /></a></div>
                    <div class="gallery-item"><a href="images/08.jpg" rel="external"><img src="images/08-thumb.jpg" alt="Image 8" /></a></div>
                    <div class="gallery-item"><a href="images/09.jpg" rel="external"><img src="images/09-thumb.jpg" alt="Image 9" /></a></div>
                </div>
            </div>
        </div>
        <div data-role="footer">
            <h4>&copy; 2011 PhotoSwipe</h4>
        </div>
    </div>
</body>
</html>

最佳答案

PhotoSwipe 有一个 modal 选项:

var options = {
    modal: false
}
var gallery = new PhotoSwipe( someElement, PhotoSwipeUI_Default, someItems, options);
gallery.init();

这使得 PhotoSwipe 容器在设置为 false 时仅采用其父容器的大小。

关于javascript - 将 PhotoSwipe 配置为不使用整个窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26512946/

相关文章:

javascript - 在Electron渲染器进程中持久化nedb到磁盘(Webpack/Electron/nedb配置问题)

javascript - jQuery 提交表单不起作用

javascript - 使用 Javascript 正则表达式,如何在某些短语之间获取值..?

javascript - 如何通过 ajax 获取一个标签而不是整页的值 - jQuery

html - CSS - 将鼠标悬停在 li a 上

html - h1 图标垂直对齐在 bootstrap 2.3.2 中不起作用

javascript - Passport.js `isAuthenticated()` 不一致的行为;应该为真时为假

javascript - 如何使用正则表达式参数化以逗号分隔的字符串?

javascript - 为什么我的路线没有加载我的 React 组件?

css - Bootstrap : positioning div block under col-xs-8 + col-xs-4 is not as expected