1

我正在使用Lightgallery,一切正常,除非我<h1>在 foreach 循环中回显标签。当我删除它时,画廊工作正常。

添加标签时唯一的问题<h1>是图像没有被加载。我只是看到预加载器永远加载。这可能是什么原因造成的?

我的代码:

<div id="lightgallery" style="border-top: 2px solid rgb(230, 230, 230);">
    <?
    $dir = $_SERVER['DOCUMENT_ROOT'].'/images/PROJECTEN/';
    $folders = array_diff(scandir($dir), array('index.html', '.', '..'));

    function scan_dir($dir) {
        $ignored = array('.', '..', '.svn', '.htaccess','index.html');

        $files = array();
        foreach (scandir($dir) as $file) {
            if (in_array($file, $ignored)) continue;
            $files[$file] = filemtime($dir . '/' . $file);
        }

        arsort($files);
        $files = array_keys($files);

        return ($files) ? $files : false;
    }

    foreach($folders as $gallerypart){
        $nounderscore = str_replace('_', ' ', $gallerypart);
        $gallery .= '<h1>'.$nounderscore.'</h1>';
        foreach(scan_dir($_SERVER['DOCUMENT_ROOT'].'/images/PROJECTEN/'.$gallerypart.'/') as $entry) {

            $gallery .= '
                <a href="http://www.website.nl/images/PROJECTEN/'.$gallerypart.'/'.$entry.'">
                    <img class="galleryimg" src="http://www.website.nl/images/PROJECTEN/'.$gallerypart.'/'.$entry.'" />
                </a>';
        }

    }
    echo $gallery;
    ?>
</div>

这是破坏它的部分:

$gallery .= '<h1>'.$nounderscore.'</h1>';
4

1 回答 1

0

我通过使用选择器而不是使用标准标记来修复它。

像这样:

<script type="text/javascript">
    $(document).ready(function() {
        $('#selector1').lightGallery({
            selector: '.item'
        });
    });
</script>

然后在循环内我添加了以下代码:

$gallery .= '
<div class="item" data-src="http://www.website.nl/images/PROJECTEN/'.$gallerypart.'/'.$entry.'">
    <img class="galleryimg" src="http://www.website.nl/images/PROJECTEN/'.$gallerypart.'/'.$entry.'" />
</div>';
于 2016-04-21T12:22:02.460 回答