dqkx69935 2016-04-20 13:18 采纳率: 100%
浏览 177
已采纳

添加h1标签时Lightgallery无法正常工作?

I am using Lightgallery and everything works, except when I echo an <h1> tag inside a foreach loop. When I remove it, the gallery works fine.

The only issue when I add the <h1> tag is that the images are not being loaded. I just see the preloader loading forever. What could be causing this?

My code:

<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>

This is the part that breaks it:

$gallery .= '<h1>'.$nounderscore.'</h1>';
  • 写回答

1条回答 默认 最新

  • dongqing483174 2016-04-21 12:22
    关注

    I fixed it by instead of using the standard markup, I used a selector.

    Like this:

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

    And then inside the loop I added the following code:

    $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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据