【问题标题】:Setting the jquery Galleria plugin to open on specific image将 jquery Galleria 插件设置为在特定图像上打开
【发布时间】:2014-02-20 03:45:13
【问题描述】:

我正在尝试在我的页面上制作简单的画廊。当网页的图库部分打开时,简单的有一些src和href标签显示的图片:

echo '<div style="float:left; margin:5px;">
    <a href="'.$link.'"><img src="'.$mini.'" title="clickclack.cz" alt="clickclack.cz" style="height:171px; border:2px solid black;" /></a>
</div>';

现在 - 当我点击其中一些图片时,我不只是想在白色背景上显示全尺寸图片。我想在 Galleria 插件中打开它,并有可能滚动到该页面上的其他图像。我无法弄清楚如何做到这一点。如果我在&lt;div id="galleria" style="height:500px;"&gt; 中用图片包装 div,当我打开图库部分时,插件会立即启动。

JS部分代码很基础:

    $(function() {
    Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
    Galleria.run('#galleria');              
});

编辑: 我找到了解决方案。根据 PHP 条件,我首先将 href 参数设置为href="?galerie&amp;inGallery&amp;index='.$i.'"。 galerie 参数只是意味着打开同一个页面 Im , index 是 while 循环中的行号(它与 Galleria 中的索引匹配), inGallery 设置 PHP 条件。通过 URL 中的 inGallery 参数,带有图片的块现在被包裹在 &lt;div id="galleria"&gt; 中,并且 href 参数是图像的实际链接。所以现在画廊页面在 Galleria 中打开了。 为了在点击的图像上打开 Galleria,我添加了 JS 功能。我的 JS 部分(也包含在条件 if(isset($_GET['inGallery'])) 中)现在看起来像这样(加上我添加了 id="fullscreen" 的链接来切换全屏):

function GetURLParameter(sParam){
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++){
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == sParam){
        return sParameterName[1];
    }
}
}
$(function() {
        var index = GetURLParameter('index');
        Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
        Galleria.run('#galleria', { show: index });
        $('#fullscreen').click(function() {
          $('#galleria').data('galleria').toggleFullscreen(); // toggles the fullscreen
        });

    });

【问题讨论】:

  • 请提供更具体的信息,尤其是js代码。您可能想要更改触发器启动库插件。
  • 我的 Galleria js 代码就是$(function() { Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js'); Galleria.run('#galleria'); });
  • 我发现可能我必须以某种方式告诉插件它应该从哪个图像索引开始......但是 Galleria 文档并没有证明很有帮助,只有非常基本的示例,没有描述,这些事情怎么办……
  • 我会尝试:$(document).on("click", "img", function(){ /*在这里调用galeria,使用$(this)对点击的图片进行操作*/} );

标签: jquery galleria


【解决方案1】:

您需要使用show method。从链接“显示指定为索引的图像。您可以随时调用此方法,图像将被放置在转换队列中。”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多