幻灯片PHP编码-图像显示不稳定
我正在尝试设置一个动态自动填充幻灯片,但我不明白我的代码出了什么问题。我知道这两种代码是分开工作的——我已经测试过了。其中一个代码用于非动态相关目录。至于动态方面,我尝试过(没有任何CSS或其他内容,文件夹中的所有图片都会显示) 我知道我的编码方式一定有问题,但我不能指出我做错了什么。我知道这与我在slideshow div中合并的PHP方面有关,类名为“box\u skitter box\u skitter\u large” 我的代码如下(全部在正文中):幻灯片PHP编码-图像显示不稳定,php,dynamic,slideshow,populate,Php,Dynamic,Slideshow,Populate,我正在尝试设置一个动态自动填充幻灯片,但我不明白我的代码出了什么问题。我知道这两种代码是分开工作的——我已经测试过了。其中一个代码用于非动态相关目录。至于动态方面,我尝试过(没有任何CSS或其他内容,文件夹中的所有图片都会显示) 我知道我的编码方式一定有问题,但我不能指出我做错了什么。我知道这与我在slideshow div中合并的PHP方面有关,类名为“box\u skitter box\u skitter\u large” 我的代码如下(全部在正文中): $(文档).ready(函数(){
$(文档).ready(函数(){
$(“.box\u skitter\u large”).skitter();
});
-
因为我对代码格式和布局有点强迫症,所以您有很多不需要的多余代码:
<?php
//this assumes the path is <current PHP file location>/images/<image files>
$directory = "images/";
//get all image files with a .jpg extension.
$images = glob( $directory . "*.jpg");
$imgs = array(); //this may have been causing you problems, view below...
// create array
foreach($images as $image){ $imgs[] = $image; }
unset($image);
//shuffle array
shuffle($imgs);
//select first 20 images in randomized array
$imgs = array_slice($imgs, 0, 20);
?>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$(".box_skitter_large").skitter();
});
</script>
<div class="box_skitter box_skitter_large">
<ul>
<li>
<?php
//display images
foreach ($imgs as $img) {
echo "<img src='".$img."' />";
}
unset($img);
?>
</li>
</ul>
</div>
$(文档).ready(函数(){
$(“.box\u skitter\u large”).skitter();
});
-
错的是你已经确定了$imgs=''
设置$img为字符串类型,然后在foreach
循环中设置$imgs[]=
,这意味着$imgs
为数组类型。现在就试试……什么是真正的“不稳定”,您在页面上显示的代码的实际问题是什么?