如何在DIV上设置左右按钮以水平滚动内容?我不需要显示滚动条.
HMTL:
<div id="browser"> <a href="#" id="left-button"><img src="left-button.jpg" /></a> <img src="thumb_1.jpg" /> <img src="thumb_2.jpg" /> <img src="thumb_3.jpg" /> <img src="thumb_4.jpg" /> <img src="thumb_5.jpg" /> <img src="thumb_6.jpg" /> <a href="#" id="right-button"><img src="right-button.jpg" /></a> </div>
CSS:
#browser { float: left; width: 200px; overflow: hidden; white-space: Nowrap; }
解决方法
做:
<div id="browser">
<a href="#" id="left-button"><img src="left-button.jpg" /></a>
<div id="content">
<img src="thumb_1.jpg" />
<img src="thumb_2.jpg" />
<img src="thumb_3.jpg" />
<img src="thumb_4.jpg" />
<img src="thumb_5.jpg" />
<img src="thumb_6.jpg" />
</div>
<a href="#" id="right-button"><img src="right-button.jpg" /></a>
</div>
<script>
$('#right-button').click(function() {
event.preventDefault();
$('#content').animate({
marginLeft: "-=200px"
},"fast");
});
</script>
然后左边的按钮相同,除了 – marginLeft:=“200px”.