【发布时间】:2016-06-17 04:38:07
【问题描述】:
我有一个幻灯片,其中包含下一个和上一个按钮(我没有使用 jquery),我需要将下一个和上一个按钮变成箭头,我不知道从哪里开始。我也无法在其他任何地方找到答案。
CSS
.slide {
display:inline-block;
position: relative;
}
.slide img {
display:block;
max-width: 100%;
height: 300px;;
width: 500px;
}
.slide img:hover + .slide-caption {
opacity: 1;
}
.slide-title {
margine:0 0 1rem;
}
.slide-caption {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 1rem;
color: white;
background-color: rgba( 0, 0, 0, 0.5 );
opacity:0;
}
.slide-caption:hover {
opacity: 1;
}
/*div.description {
color:blue;
}*/
div.prev {
text-align: left;
}
div.next {
margin-left:400px;
margin-top:0px;
}
PHP
while ($row = $result->fetch_assoc()) {
$pic_array[$count] = $row['pic_url'];
$titles[$count] = $row['title'];
$descriptions[$count] = $row['description'];
$count++;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['action'] == 'Previous') {
$index = $_POST['i'];
if ($index == 0) {
$index = count($pic_array) - 1;
echo "<div class='slide'>
<img src= ".$dir.$pic_array[$index]." />
<div class='slide-caption'>
<h3 class='slide-title'> $titles[$index] </h3>
<p> $descriptions[$index] </p>
</div>
</div>";
}
else {
$index--;
echo "<div class='slide'>
<img src= ".$dir.$pic_array[$index]." />
<div class='slide-caption'>
<h3 class='slide-title'> $titles[$index] </h3>
<p> $descriptions[$index] </p>
</div>
</div>";
}
echo '<form action="gallery.php" method="post">
<input type="submit" name="action" value="Previous">
<input type="submit" name="action" value="Next">';
echo "<input type='hidden' name='i' value= '$index'' >";
}
if ($_POST['action'] == "Next") {
$index = $_POST['i'];
if ($index == count($pic_array) - 1) {
$index = 0;
echo "<div class='slide'>
<img src= ".$dir.$pic_array[$index]." />
<div class='slide-caption'>
<h3 class='slide-title'> $titles[$index] </h3>
<p> $descriptions[$index] </p>
</div>
</div>";
}
else {
$index++;
echo "<div class='slide'>
<img src= ".$dir.$pic_array[$index]." />
<div class='slide-caption'>
<h3 class='slide-title'> $titles[$index] </h3>
<p> $descriptions[$index] </p>
</div>
</div>";
}
echo '<form action="gallery.php" method="post">
<input type="submit" name="action" value="Previous">
<input type="submit" name="action" value="Next">';
echo "<input type='hidden' name='i' value= '$index' >";
}
} else {
$index = 1;
echo "<div class='slide'>
<img src= ".$dir.$pic_array[$index]." />
<div class='slide-caption'>
<h3 class='slide-title'> $titles[$index] </h3>
<p> $descriptions[$index] </p>
</div>
</div>";
echo '<form action="gallery.php" method="post">
<div class="prev">
<input type="submit" name="action" value="Previous">
</div>
<div class="prev">
<input type="submit" name="action" value="Next">
</div>';
echo "<input type='hidden' name='i' value= '$index' >";
/*echo "<div class='description'
<p> $descriptions[$index] </p>
</div>";*/
}
【问题讨论】:
-
做一个 if 语句。如果 page 大于 1,则回显 Next Page 包裹在右箭头图标中。
-
并在 URL 中传递页面值,然后执行获取请求以显示该页面...
-
输入也可以是图像,你知道...
-
在您的代码末尾有 echo
-
我并没有完全关注 Levi。