document.querySelector('input').addEventListener('input', function(){
document.querySelector('.box').scrollLeft = this.value;
})
.box{
width: 320px;
height: 100px;
border:1px solid red;
overflow: scroll;
direction: rtl; /*
}
.box::before{ content:''; display:block; width:400%; height:1px; }
另一答案
我不知道任何只有CSS的解决方案,但你可以使用Jquery来改变滚动条的初始位置,如下所示:
$(document).ready(function(){
$('#box').scrollLeft($(this).height())
})
另一答案
使用javascript,您可以在页面加载时设置scrollLeft属性(使用el.scrollLeft = el.scrollWidth - el.clientWidth;)。
另一答案
如果您在最顶层答案的文本末尾添加右括号,则会出现意外行为。 (在Chrome 54中测试过)
另一答案
你可以用一行jQuery来做到这一点:
$("#box").scrollLeft(480);
另一答案
我一直在一个项目工作,对我来说非常好,这样:
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;