gpt4 book ai didi

jquery - 使用按钮水平滚动 div

转载 作者:行者123 更新时间:2023-12-03 22:20:52 24 4
gpt4 key购买 nike

如何在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"。

关于jquery - 使用按钮水平滚动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8561124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com