【发布时间】:2018-05-15 05:31:35
【问题描述】:
你好 stackoverflowers,
我正在使用 prettyPhoto 显示来自使用 PHP、Jquery 的文件夹中的图像。
当我使用下面键入的代码时,prettyPhoto 运行良好。
<div class="row page-row">
<a class="prettyphoto col-md-3 col-sm-3 col-xs-6" rel="prettyPhoto[gallery]" href="gallery/Garba 2017/IMG_8237.JPG"><img class="img-responsive img-thumbnail" src="gallery/Garba 2017/IMG_8237.JPG" alt="" /></a>
<a class="prettyphoto col-md-3 col-sm-3 col-xs-6" rel="prettyPhoto[gallery]" href="gallery/Garba 2017/IMG_8238.JPG"><img class="img-responsive img-thumbnail" src="gallery/Garba 2017/IMG_8238.JPG" alt="" /></a>
<a class="prettyphoto col-md-3 col-sm-3 col-xs-6" rel="prettyPhoto[gallery]" href="gallery/Garba 2017/IMG_8239.JPG"><img class="img-responsive img-thumbnail" src="gallery/Garba 2017/IMG_8239.JPG" alt="" /></a>
<a class="prettyphoto col-md-3 col-sm-3 col-xs-6" rel="prettyPhoto[gallery]" href="gallery/Garba 2017/IMG_8241.JPG"><img class="img-responsive img-thumbnail" src="gallery/Garba 2017/IMG_8241.JPG" alt="" /></a>
</div>
但是,当我尝试使用 JQuery 和 PHP 从文件夹中动态加载相同的图像时,我可以看到加载的图像,但是当我单击独立打开的图像时,prettyPhoto 效果不起作用。
这是我用来从文件夹加载图像的 PHP 和 JQuery 代码。
<div class="row page-row" id="libImages">
<div id='loaderImage'><img src="img/loader.gif" alt="Site Logo" class="img-responsive" /></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("a[rel^='prettyPhoto']").prettyPhoto();
showImages();
function showImages(){
setTimeout("$('#libImages').load('gallery/Garba2017.php', function(){ $('#loaderImage').hide(); });", 1000);
}
});
//onready ends here
</script>
Garba2017.php
$filenameArray = [];
$handle = opendir(dirname(realpath(__FILE__)).'/Garba 2017/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "gallery/Garba 2017/$file");
}
}
shuffle($filenameArray);
$count = count($filenameArray);
$num = 1;
for ($i = 0; $i < $count; $i++) {
echo '<a class="prettyphoto col-md-3 col-sm-3 col-xs-6" rel="prettyPhoto[gallery]" href="'.$filenameArray[$i].'"><img class="img-responsive img-thumbnail" src="'.$filenameArray[$i].'" alt="GARBA IMAGE '.$num.'" /></a>';
$num++;
}
这是不使用 JQuery 和 PHP 的页面链接 --> prettyPhoto Working http://navjivancollege.ac.in/Garba%202017.php
这是使用 JQuery 和 PHP 的页面链接 --> prettyPhoto 不工作 http://navjivancollege.ac.in/Garba%202017%202.php
请指导我在哪里犯错...
【问题讨论】:
标签: php jquery gallery prettyphoto