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

Slide-over feature #197

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
464 changes: 47 additions & 417 deletions README.md

Large diffs are not rendered by default.

61 changes: 54 additions & 7 deletions dist/slideout.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/slideout.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,29 @@ body {
bottom: 0;
right: 0;
z-index: 0;
display: none;

width: 256px;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
display: none;
}

.slideout-right-menu {
position: fixed;
left: auto;
right: 0;
}

.slideout-slide-menu {
left: -256px;
display: block;
z-index: 10;
will-change: transform;
}

.slideout-slide-menu.slideout-right-menu {
right: -256px;
left: auto;
}

.slideout-panel {
Expand Down
59 changes: 53 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ function Slideout(options) {
this._orientation = options.side === 'right' ? -1 : 1;
this._translateTo *= this._orientation;

// Slideover fork feature
this._mode = options.mode || 'push';

// Init touch events
if (this._touch) {
this._initTouchEvents();
Expand All @@ -100,7 +103,14 @@ Slideout.prototype.open = function() {
this._translateXTo(this._translateTo);
this._opened = true;
setTimeout(function() {
self.panel.style.transition = self.panel.style['-webkit-transition'] = '';

// Slideover fork feature
if(this._mode === 'push') {
self.panel.style.transition = self.panel.style['-webkit-transition'] = '';
} else {
self.menu.style.transition = self.menu.style['-webkit-transition'] = '';
}

self.emit('open');
}, this._duration + 50);
return this;
Expand All @@ -120,7 +130,14 @@ Slideout.prototype.close = function() {
this._opened = false;
setTimeout(function() {
html.className = html.className.replace(/ slideout-open/, '');
self.panel.style.transition = self.panel.style['-webkit-transition'] = self.panel.style[prefix + 'transform'] = self.panel.style.transform = '';

// Slideover fork feature
if(this._mode === 'push') {
self.panel.style.transition = self.panel.style['-webkit-transition'] = self.panel.style[prefix + 'transform'] = self.panel.style.transform = '';
} else {
self.menu.style.transition = self.menu.style['-webkit-transition'] = self.menu.style[prefix + 'transform'] = self.menu.style.transform = '';
}

self.emit('close');
}, this._duration + 50);
return this;
Expand All @@ -145,15 +162,29 @@ Slideout.prototype.isOpen = function() {
*/
Slideout.prototype._translateXTo = function(translateX) {
this._currentOffsetX = translateX;
this.panel.style[prefix + 'transform'] = this.panel.style.transform = 'translateX(' + translateX + 'px)';

// Slideover fork feature
if(this._mode === 'push') {
this.panel.style[prefix + 'transform'] = this.panel.style.transform = 'translateX(' + translateX + 'px)';
} else {
this.menu.style[prefix + 'transform'] = this.menu.style.transform = 'translateX(' + translateX + 'px)';
}

return this;
};

/**
* Set transition properties
*/
Slideout.prototype._setTransition = function() {
this.panel.style[prefix + 'transition'] = this.panel.style.transition = prefix + 'transform ' + this._duration + 'ms ' + this._fx;

// Slideover fork feature
if(this._mode === 'push') {
this.panel.style[prefix + 'transition'] = this.panel.style.transition = prefix + 'transform ' + this._duration + 'ms ' + this._fx;
} else {
this.menu.style[prefix + 'transition'] = this.menu.style.transition = prefix + 'transform ' + this._duration + 'ms ' + this._fx;
}

return this;
};

Expand Down Expand Up @@ -198,7 +229,15 @@ Slideout.prototype._initTouchEvents = function() {
self._moved = false;
self._opening = false;
self._startOffsetX = eve.touches[0].pageX;
self._preventOpen = (!self._touch || (!self.isOpen() && self.menu.clientWidth !== 0));


// Slideover fork feature
if(self._mode === 'push') {
self._preventOpen = (!self._touch || (!self.isOpen() && self.menu.clientWidth !== 0));
} else {
self._preventOpen = (!self._touch || (!self.isOpen() && self.menu.style.transform !== ''));
}

};

this.panel.addEventListener(touch.start, this._resetTouchFn);
Expand Down Expand Up @@ -265,7 +304,15 @@ Slideout.prototype._initTouchEvents = function() {
html.className += ' slideout-open';
}

self.panel.style[prefix + 'transform'] = self.panel.style.transform = 'translateX(' + translateX + 'px)';

// Slideover fork feature
if(self._mode === 'push') {
self.panel.style[prefix + 'transform'] = self.panel.style.transform = 'translateX(' + translateX + 'px)';
} else {
self.menu.style[prefix + 'transform'] = self.menu.style.transform = 'translateX(' + translateX + 'px)';
}


self.emit('translate', translateX);
self._moved = true;
}
Expand Down
Loading