我试图强制 div 水平滚动,但我需要它平滑滚动,而不仅仅是跳到我需要它去的地方。
这就是我正在使用的。
<html>
<img onclick="scroll();" class="slidearrows" src="images/left.png" />
<html/>
<script>
function scroll() {
document.getElementById('scrl-bar').scrollLeft = 1200;
}
<script>
现在这可以工作,但它只是跳跃并且进展不顺利。谁能帮我让它顺利进行吗?
最佳答案
使用 jquery:
$('.slidearrows').on('click', function () {
$('html,body').animate({scrollLeft: 0}, 1800); // 1800 is the milliseconds to scroll
});
关于JAVASCRIPTscrollLeft平滑滚动而不跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45628376/