我有一个<div>
包含图像(在div's
内),您可以通过点击nav
控件进行查看。 我的问题是我怎样才能从一个特定的图像启动(加载)图像的div? 那么例如,从数组中的第三个图像开始?开始图像div
HTML:
<div id="imagePanel">
<div id="images">
<div> <img src="http://placehold.it/250x387/bb5533/000000"></div>
<div> <img src="http://placehold.it/250x387/ffff33/000000"></div>
<div> <img src="http://placehold.it/250x387/feef33/000000"></div>
<div> <img src="http://placehold.it/250x387/dd4433/000000"></div>
</div>
</div>
<div id="imageNav">
<a id="prev">prev</a><br />
<a id="next">next</a>
</div>
JS:
var imgsize = 387;
$('#images').data('top',0);
len = $('#images').children().length;
$('#images').data('max',len * (-imgsize));
$(document).ready(function() {
$('#prev').click(function(){
currTop = $('#images').data('top') + (imgsize);
if (currTop == imgsize) {
return;
}
$('#images').css('top',currTop.toString()+"px");
$('#images').data('top',currTop);
});
$('#next').click(function(){
currTop = $('#images').data('top') - (imgsize);
if (currTop == $('#images').data('max')) {
return;
}
$('#images').css('top',currTop.toString()+"px");
$('#images').data('top',currTop);
});
});
CSS:
#imagePanel{
width:280px;
height:390px;
background:#aa44dd;
border:4px solid #bbbb33;
overflow-x:hidden;
overflow-y:hidden;
margin:auto;
}
#images{
width:250px;
position:relative;
overflow:hidden;
text-align:center;
margin-left:auto;
margin-right:auto;
padding:0px 0px 0px 0px;
}
#images > div {
height:387px;
margin:0 auto;
padding:0px 0px 0px 0px;
}
谢谢。我被困在一段时间了。 – user1648449 2013-03-12 05:24:39