Scroll horizontally starting from right to left with CSS overflow:scroll

后端 未结 6 1856
天命终不由人
天命终不由人 2020-12-16 12:07

So I am wondering if there is a possibility to have a different starting position with the overflow:scroll value;

When you start scrolling in a div

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 12:29

    You can of course use direction:rtl

    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;  /* <-- the trick */
    }
    
    .box::before{ content:''; display:block; width:400%; height:1px; }

    FiddleDemo

    This may be useful using direction http://css-tricks.com/almanac/properties/d/direction/

提交回复
热议问题