如何使用上一个/下一个按钮循环浏览图像
How do I loop through images with Previous/Next buttons?
我能够让图像循环播放,但现在当我单击"上一个"或"下一个"链接时,我存储图像的文件夹每次都会弹出。关于为什么会发生这种情况或如何阻止它的任何想法?
剧本
<script type="text/javascript">
/* <![CDATA[ */
function changeDisplay(curLine) {
curLine.style.color = "red";
curLine.style.fontWeight = "bold";
}
function restoreDisplay(curLine) {
curLine.style.color = "blue";
curLine.style.fontWeight = "normal";
}
var curImage = 1;
function changeImage(which) {
for (var i=0; i < 5; ++i) {
document.getElementById("image"+i).style.display = "none";
}
if (which < 1)
which = 5;
if (which > 5)
which = 1;
document.getElementById("image"+which).style.display = "block";
curImage = which;
}
/* ]]> */
</script>
目录
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link type="text/css" rel="stylesheet" href="project.css" />
</head>
<body>
<div>
<table style="border:none" class="menu">
<tr>
<td><a href="Index.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Home</a></td>
<td class="menupipe">|</td>
<td><a href="Specials.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Specials</a></td>
<td class="menupipe">|</td>
<td><a href="Tools.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Tools</a></td>
<td class="menupipe">|</td>
<td><a href="Prices.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Prices</a></td>
<td class="menupipe">|</td>
<td><a href="Order.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Shop</a></td>
</tr>
</table>
</div>
<div>
<p style="font-weight:bold; font-size:20px">With winter approaching, every homeowner wants to be prepared for the snow and ice! We are now running a sale on a few items that will help handle the harsh winter conditions. Take a look at our prices and make sure you stock up. Click on the images below for more information.</p>
</div>
<div id="image" style="display:block">
<img src="images/deicer.jpg" height="300" width="300" alt="deicer" />
</div>
<div id="image" style="display:none">
<img src="images/snowblower.jpg" height="300px" width="300px" alt="snowblower" />
</div>
<div id="image" style="display:none">
<img src="images/icemelt.jpg" height="300px" width="250px" alt="icemelt" />
</div>
<div id="image" style="display:none">
<img src="images/shovel.jpg" height="225px" width="225px" alt="shovel" />
</div>
<div id="image" style="display:none">
<img src="images/scraper.jpg" height="124" width="124" alt="scraper" />
</div>
<button type="button" onclick="changeImage(curImage - 1)">Previous</button>
<button type="button" onclick="changeImage(curImage + 1)">Next</button>
</body>
</html>
所有映像容器
<div id="image" style="display:none">
具有相同的 ID 并且与格式图像不对应#
同时将以下循环从
for (var i=0; i < 5; ++i) {
document.getElementById("image"+i).style.display = "none";
}
自
for (var i=0; i < 5; ++i) {
document.getElementById("image"+ (i + 1)).style.display = "none";
}
将索引 (1 - 5) 添加到所有图像div,例如:
<div id="image1" style="display:block">
在循环中更改索引以使其无处不在1 - 5
。或者将所有内容更改为0 - 4
.
我通过向每个图像容器添加 1,2,3,4 来让它工作。
我的版本如下
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link type="text/css" rel="stylesheet" href="project.css" />
<script type="text/javascript">
/* <![CDATA[ */
function changeDisplay(curLine) {
curLine.style.color = "red";
curLine.style.fontWeight = "bold";
}
function restoreDisplay(curLine) {
curLine.style.color = "blue";
curLine.style.fontWeight = "normal";
}
var curImage = 1;
function changeImage(which) {
for (var i=0; i < 5; ++i) {
document.getElementById("image"+i).style.display = "none";
}
if (which < 1)
which = 5;
if (which > 5)
which = 1;
document.getElementById("image"+which).style.display = "block";
curImage = which;
}
/* ]]> */
</script>
</head>
<body>
<div>
<table style="border:none" class="menu">
<tr>
<td><a href="Index.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Home</a></td>
<td class="menupipe">|</td>
<td><a href="Specials.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Specials</a></td>
<td class="menupipe">|</td>
<td><a href="Tools.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Tools</a></td>
<td class="menupipe">|</td>
<td><a href="Prices.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Prices</a></td>
<td class="menupipe">|</td>
<td><a href="Order.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Shop</a></td>
</tr>
</table>
</div>
<div>
<p style="font-weight:bold; font-size:20px">With winter approaching, every homeowner wants to be prepared for the snow and ice! We are now running a sale on a few items that will help handle the harsh winter conditions. Take a look at our prices and make sure you stock up. Click on the images below for more information.</p>
</div>
<div id="image0" style="display:block">
<img src="http://placehold.it/350/ffffff/000000">
</div>
<div id="image1" style="display:none">
<img src="http://placehold.it/350/ffffff/000000">
</div>
<div id="image2" style="display:none">
<img src="http://placehold.it/350/ffffff/000000">
</div>
<div id="image3" style="display:none">
<img src="http://placehold.it/350/ffffff/000000">
</div>
<div id="image4" style="display:none">
<img src="http://placehold.it/350/ffffff/000000">
</div>
<button type="button" onclick="changeImage(curImage - 1)">Previous</button>
<button type="button" onclick="changeImage(curImage + 1)">Next</button>
</body>
</html>
相关文章:
- 循环浏览多个身体背景图像
- 单击按钮时循环浏览匹配的表
- 使用Razor/C#循环浏览HTML表以获得每个<tr>
- 玉循环浏览文件目录
- 循环浏览JavaScript对象并记录其属性
- 在 Jquery 上循环浏览类以制作动画
- 循环浏览页面上所有选中的复选框并将id拉入数组不起作用
- 如何循环浏览页面源中的所有文本框元素并查找所有这些文本框的名称
- Javascript循环浏览图像
- 使用javascript循环浏览asp.net单选按钮列表以获取所选值和文本
- 如何告诉CasperJS循环浏览一系列页面
- 基于缩略图在路径中循环浏览图像
- 如何循环浏览JSON列表
- 循环浏览视频并在每个视频后刷新
- 如何模拟单击事件以延迟循环浏览幻灯片
- 使用 JQuery 循环浏览 JavaScript 中的数组
- 循环浏览 base64 图像并保存为 pdf
- Flickity gallery - 如何循环浏览一次然后停止自动播放
- 如何重复循环浏览 JavaScript 对象
- 搜索后循环浏览数组