我正在尝试创建一个图像库,其中顶部会有一个大图像,底部会有一些缩略图图像。让我参考我在这里提出的最后一个问题。
Image Gallery Using php css and javascript
所以我编辑了上面的代码并添加了explode功能和MySQL数据库。由于我在一个页面上有超过1个图库(由于类别)。我已经以这种格式存储了图像名称(reception.jpg?reception2.jpg?reception3.jpg),它存储在myphpadmin的img列下。但是,当我尝试应用更改时,似乎php / html和css代码一起工作正常。但它似乎也无法读取我放在页面最底部的脚本标记。 JS代码包含与上面链接相同的代码。你知道我错在哪里吗?它能够阅读其余部分。和悬停效果工作。就是这样,点击时不会选择缩略图。我尝试在不同的页面上重新制作它,只要脚本标记位于 head 标记
内,它就能正常工作这是我做的修订
<?php
$gallery = $value['img'];
$gallery = explode("?", $gallery);
if(!empty($gallery)) { ?>
<div class="eight-eight" id="gHolder">
<div class="eight-eight" id="theBigImageHolder">
<img src="includes/images/<?php echo $gallery[0]; ?>" id="bigImage">
</div>
<div class="eight-eight" id="thumbnailsHolder">
<?php foreach($gallery as $key => $item){ ?>
<img src="includes/images/<?php echo $item; ?>">
<?php } ?>
</div>
</div>
<?php } ?>
这是任何人都会问的完整代码
require_once 'includes/templates/header.php';
require_once 'core/connection.php';
$facility = new Facility;
$facilities = $facility->all();
?>
<!-- General Public View -->
<div class="container">
<?php include_once 'includes/templates/banner.php'; ?>
<div class="full">
<span class="eight-eight">
<?php include_once 'includes/templates/nav.php'; ?>
</span>
</div>
<div class="full">
<h1 id="catchphrase">Facilities</h1>
</div>
<div class="full facilities">
<?php
foreach ($facilities as $key => $value) { ?>
<span class="four-eight grid">
<h2><?php echo $value['name'];?></h2>
<!---Start Image Gallery -->
<?php
$gallery = $value['img'];
$gallery = explode("?", $gallery);
if(!empty($gallery)) { ?>
<div class="eight-eight" id="gHolder">
<div class="eight-eight" id="theBigImageHolder">
<img src="includes/images/<?php echo $gallery[0]; ?>" id="bigImage">
</div>
<div class="eight-eight" id="thumbnailsHolder">
<?php foreach($gallery as $key => $item){ ?>
<img src="includes/images/<?php echo $item; ?>">
<?php } ?>
</div>
</div>
<?php } ?>
<!---End Image Gallery -->
<p class="eight-eight"><?php echo $value['description'];?></p>
</span>
<?php }
?>
</div>
<?php include_once 'includes/templates/footer.php'; ?>
</div>
<?php }
?>
<script type="text/javascript">
var doi = '2015/10/15';
$('#clock').countdown(doi, function(event) {
$(this).html(event.strftime('%D Days %H:%M:%S')); });
</script>
<script type="text/javascript">
function imgFunc(){
var bigImage = document.getElementById("bigImage");
var thumbnailsHolder = document.getElementById("thumbnailsHolder");
thumbnailsHolder.addEventListener("click",function(event){
if (event.target.tagName == "IMG") {
bigImage.src = event.target.src;
}
}, false);
}
window.addEventListener("load",imgFunc,false);
</script>