Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rtl support #366

Closed
wants to merge 1 commit into from
Closed

Add rtl support #366

wants to merge 1 commit into from

Conversation

mostafakazemi
Copy link

It solves issue #345
The example in the source would work after PR merged.
For testing purpose see here
Also we should propose to when direction is rtl in some browser's scrollLeft start with zero to positive number and in others start with negative number to zero

.idea/.gitignore Outdated
@@ -0,0 +1,8 @@
# Default ignored files
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure .idea/ is ignored properly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I solved it

docs/docs/README.md Show resolved Hide resolved
Comment on lines 156 to 223
```html
<div id="app">
<div>
<div>
<ul>
<li v-for="(item, index) in list" v-scroll-to="'#item' + index ">{{ item }}</li>
</ul>
</div>

<div class="items" id="items">
<div class="item" v-for="(item, index) in list" :id="'item' + index" v-scroll-to="'#item' + index ">
<h1>{{ item }}</h1>
</div>
</div>
</div>
</div>
```

```js
Vue.use(VueScrollTo, {
container: "#items",
duration: 500,
easing: "ease",
offset: 0,
force: true,
cancelable: true,
onStart: false,
onDone: false,
onCancel: false,
x: true,
y: false,
rtl: true,
})

new Vue({
el: '#app',
data() {
return {
list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
}
},
methods: {
}
})
```

``` css
body {
direction: rtl;
}

li {
display: inline-block;
margin: 10px:
cursor: pointer;
border: 1px solid #ff4500;
padding: .5rem;
width:20px;
text-align: center;
}

.items {
margin-right: 10%;
max-height: 300px;
max-width: 50%;
overflow: auto;
display: flex;
}

.item {
min-height: 100px;
border: 1px solid #000000;
margin-left: 5rem;
padding: 1rem;
min-width: 150px;
text-align: center;
}
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify the example code (keep it as is in the jsfiddle).

Perhaps something like

<button v-scroll-to="{ 
        el: '#element',
        rtl: true,
        container: '#container'
    }">
    Scroll in a RTL container
</button>

Comment on lines +196 to +201
if (
container.scrollLeft <= 0 &&
typeof window.scrollPositive === 'undefined'
)
targetX -= container.scrollWidth - container.offsetWidth
else window.scrollPositive = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add braces to the if/else branches.

I couldn't find any references to window.scrollPositive, do we need it here? Isn't just container.scrollLeft <= 0 enough?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we need it. In some browsers when the direction is rtl, `scrollLeft start with negative number to zero.
We should define scroll start with zero or negative

Comment on lines +151 to +155
if (rtl) {
let childrens = [].slice.call(container.children)
let index = Array.prototype.indexOf.call(childrens.reverse(), element)
element = childrens.reverse()[index]
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why this is needed? This seems like a potential performance bottleneck.

Perhaps we can improve this - just need to understand why it's needed!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If direction reverse we should to scroll element that has reverse index

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we handle items that are not the same width?

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants