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
the default behaviour is to scroll from left to right:
JavaScript
x
2
1
|<--Scrollbar-Starting-Left-->_________________________________________________|
2
would it possible that it starts at the right?
JavaScript
1
2
1
|_________________________________________________<--Scrollbar-Starting-Right-->|
2
In my example the red
and green
items are first visible, I’d like the green
and blue
item to be visible first 🙂
I’ve tried direction:rtl;
but no luck
Advertisement
Answer
You can of course use direction:rtl
JavaScript
1
3
1
document.querySelector('input').addEventListener('input', function(){
2
document.querySelector('.box').scrollLeft = this.value;
3
})
JavaScript
1
9
1
.box{
2
width: 320px;
3
height: 100px;
4
border:1px solid red;
5
overflow: scroll;
6
direction: rtl; /* <-- the trick */
7
}
8
9
.box::before{ content:''; display:block; width:400%; height:1px; }
JavaScript
1
3
1
<div class='box'></div>
2
<br>
3
<input placeholder='scrollLeft value'>
This may be useful using direction http://css-tricks.com/almanac/properties/d/direction/