【发布时间】:2020-12-22 17:48:40
【问题描述】:
我刚刚看到 Vlad Danila 的回答,但无法重现平滑滚动效果。谁能帮帮我?
这是我整理的示例代码 sn-p:
const buttonRight = document.getElementById('slideRight');
const buttonLeft = document.getElementById('slideLeft');
buttonRight.onclick = function() {
document.getElementById('container').scrollLeft += 20;
};
buttonLeft.onclick = function() {
document.getElementById('container').scrollLeft -= 20;
};
#container {
width: 145px;
height: 100px;
border: 1px solid #ccc;
overflow-x: scroll;
}
#content {
width: 250px;
background-color: #ccc;
}
<div id="container">
<div id="content">Click the buttons to slide horizontally!</div>
</div>
<button id="slideLeft" type="button">Slide left</button>
<button id="slideRight" type="button">Slide right</button>
提前致谢!
【问题讨论】:
标签: javascript html css scroll