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 #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions example/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ if (!$('.demo').length) return;
});
})();

(function distance() {
Flipsnap('#demo-rtl .flipsnap', {
distance: 230,
isRTL: true
});
})();

(function maxPoint() {
Flipsnap('#demo-maxPoint .flipsnap', {
distance: 160, // 80px * 2
Expand Down
13 changes: 13 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ <h3>distance</h3>
</div>
</section>

<section class="demo" id="demo-rtl">
<h3>rtl</h3>
<div class="viewport" dir="rtl">
<div class="flipsnap flex">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
</div>
</section>

<section class="demo" id="demo-maxPoint">
<h3>maxPoint</h3>
<div class="viewport">
Expand Down
11 changes: 11 additions & 0 deletions example/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ h1, h2, h3 {
padding: 30px 0;
-webkit-transform: translateZ(0); }

.flex {
display: -webkit-box;
display: -webkit-flex;
display: flex;
}
.flex > * {
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
}

.flipsnap {
width: 1195px;
/* 230px(item) * 5 + 45px(padding) */
Expand Down
9 changes: 8 additions & 1 deletion flipsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Flipsnap.prototype.init = function(element, opts) {
opts = opts || {};
self.distance = opts.distance;
self.maxPoint = opts.maxPoint;
self.isRTL = opts.isRTL || document.documentElement.getAttribute('dir') === 'rtl';
self.disableTouch = (opts.disableTouch === undefined) ? false : opts.disableTouch;
self.disable3d = (opts.disable3d === undefined) ? false : opts.disable3d;
self.transitionDuration = (opts.transitionDuration === undefined) ? '350ms' : opts.transitionDuration + 'ms';
Expand Down Expand Up @@ -204,7 +205,9 @@ Flipsnap.prototype.refresh = function() {
else {
self._distance = self.distance;
}

if (self.isRTL) {
self._distance = -self._distance;
}
// setting maxX
self._maxX = -self._distance * self._maxPoint;

Expand Down Expand Up @@ -404,6 +407,10 @@ Flipsnap.prototype._touchEnd = function(event, type) {
}

var newPoint = -self.currentX / self._distance;

if (self.isRTL) {
self.directionX = -self.directionX;
}
newPoint =
(self.directionX > 0) ? Math.ceil(newPoint) :
(self.directionX < 0) ? Math.floor(newPoint) :
Expand Down