我正在尝试创建一个图片库,其中包含一个大图像和可以通过滚动查看的小缩略图。我希望能够以两种方式在中间改变图片:(1)使用位于大图像顶部的箭头,(2)通过点击小缩略图。我被困在步骤(1)已经走了这么远了下面的代码:如何使用缩略图和箭头创建图片库
HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="1.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="1.js"></script>
</head>
<body>
<!--part a-->
<div id="imag">
<div class="imageDiv">
<div>
<img src="http://www.talkandroid.com/wallpapers/images/1/small/1_3D_Landscape__54_.jpg" class="image"/>
</div>
<div>
<img src="http://www.ifpindia.org/ecrire/upload/mount_landscape01.jpg" class="image"/>
</div>
<div>
<img src="http://images.all-free-download.com/images/wallpapers_thum/gran_paradiso_wallpaper_landscape_nature_wallpaper_1538.jpg" class="image" />
</div>
<div>
<img src="http://images.all-free-download.com/images/wallpapers_thum/desert_wallpaper_landscape_nature_wallpaper_1062.jpg" class="image" />
</div>
<div>
<img src="http://www.bathnes.gov.uk/sites/default/files/siteimages/Environment/Trees-and-Woodlands/16cotswolds1-200x150.jpeg" class="image" />
</div>
<div>
<img src="http://images.all-free-download.com/images/wallpapers_thum/amazing_sunset_wallpaper_landscape_nature_wallpaper_1506.jpg" class="image" />
</div>
<div>
<input type="image" src="right arrow.png" class="rightarrow" width="10" height="35"/>
</div>
<div>
<input type="image" src="left arrow.png" class="leftarrow" width="10" height="35"/>
</div>
</div>
</div>
<!--part a-->
<!--part b-->
<div id="box">
<div class="area">
<img src="http://www.talkandroid.com/wallpapers/images/1/small/1_3D_Landscape__54_.jpg"/>
<img src="http://www.ifpindia.org/ecrire/upload/mount_landscape01.jpg"/>
<img src="http://images.all-free-download.com/images/wallpapers_thum/gran_paradiso_wallpaper_landscape_nature_wallpaper_1538.jpg"/>
<img src="http://images.all-free-download.com/images/wallpapers_thum/desert_wallpaper_landscape_nature_wallpaper_1062.jpg"/>
<img src="http://www.bathnes.gov.uk/sites/default/files/siteimages/Environment/Trees-and-Woodlands/16cotswolds1-200x150.jpeg"/>
<img src="http://images.all-free-download.com/images/wallpapers_thum/amazing_sunset_wallpaper_landscape_nature_wallpaper_1506.jpg"/>
</div>
</div>
<!--part b-->
</body>
</html>
CSS:
#imag {
float:left;
padding:5px;
height:338px;
width:450px;
}
.rightarrow {
position: absolute;
width:40px;
top: 10px;
left:400px;
}
.leftarrow {
position: absolute;
width:40px;
top: 10px;
left: 0px;
}
#box {
width: 222px;
height: 343px;
overflow-y: scroll;
overflow-x: hidden;
}
.area img {padding-bottom: 5px;}
JS:
$(document).ready(function() {
$('img:not(:first)').hide();
$(".rightarrow").click(function() {
$('img:not(:last):visible').
hide().
parent().
next().
children().
show();
});
$(".leftarrow").click(function() {
$('img:not(:first):visible').
hide().
parent().
prev().
children().
show();
});
});
我刚刚开始学习HTML,所以我不太确定这是否是实现这一目标的最佳方法,但这是我迄今为止所掌握的。现在问题是,如果我删除b部分,部分a工作正常。如果我从代码的标题部分删除a部分和js行,那么b部分工作正常。所以我的问题是如何将两个零件组合在一起,以便它们一起正确工作?
你能在捣鼓这[jsffiddle.net](http://jsfiddle.net) –
是的,我试着拨弄,但我得到了相同的结果 – oliveirano25