我的目标是制作幻灯片。我在这里只有1张图片,并计划在稍后使用。制作数组幻灯片Javascript
<!DOCTYPE html>
<html onmousedown='event.preventDefault();'>
<head>
<title> Slides </title>
<meta charset='utf-8'>
<style>
table{
margin: 1.5in;
}
.arrow{
color: blue;
cursor: pointer;
}
我试图让水平和垂直居中的图像类640 x 540像素。我想避免内部填充。不知道它是否正确。
.img{
height: 540px;
width: 640px;
position: relative;
}
对于图像元素本身我没有保证金,是100%宽,有一个1像素纯黑色边框。
#image{
width: 100%;
border: solid 1px;
border-color: black;
}
</style>
<script>
我想使2全局变量,“图像”和“imgidx”。 -images - 以图像目录中的图像路径作为字符串填充的数组。
-imgidx - 一些初始设置为0
接下来我要填写以下功能。
- 增加或减少imgidx。
-将img元素上的'src'属性(由id'img'标识)设置为图像[imgidx]上的图像。如果imgidx>图像数组中的图像数量,它应该回到零。如果它低于零,它应该设置为小于数组长度的1。
function previmg() {
}
function nextimg() {
}
</script>
</head>
<body>
<table>
<tr>
<!-- Clicking on the arrows should change the image being displayed: -->
<td class='arrow' onclick='previmg();'> «
<td class='image'><img id='img' src='https://img-9gag-fun.9cache.com/photo/appxzbM_460s.jpg'>
<td class='arrow' onclick='nextimg();'> »
</table>
</body>
</html>
所以你想改变'img'的src或你想要的图像走动? –
我打算在以后重用不同图像的代码。我想能够前进和后退。 – HTMLnoobcs17001
你会有更多的'img'还是只有那个'img',它会根据你点击的箭头改变它的src? –