Skip to content

Instantly share code, notes, and snippets.

@urakey
Last active August 29, 2015 13:58
Show Gist options
  • Save urakey/10216991 to your computer and use it in GitHub Desktop.
Save urakey/10216991 to your computer and use it in GitHub Desktop.
途中:SlideMenu
;(function($)
{
'use strict';
/**
* @class SlideMenu
*/
function SlideMenu() {
this.$slideMenu = $('#slideMenu');
this.$slideContentsWrap = $('#slideContentsWrap');
this.$slideMenuOpen = $('#slideMenuOpen');
this.$slideMenuClose = $('#slideMenuClose');
this._init.apply(this);
}
SlideMenu.prototype = {
// constants
DISTANCE: 250,
timer: null,
// 読み込み初期の実行処理
_init: function() {
this.resize();
this.isOpen = false;
this.$slideContentsWrap.addClass('init');
this.$slideMenuOpen.on('click', $.proxy(this._slideMenuOpenClick, this));
this.$slideContentsWrap.on('click', $.proxy(this._slideMenuCloseClick, this));
},
// リサイズイベント
resize: function() {
this.$slideMenu.css({ minHeight: $(window).height() + 'px' });
},
// スライドメニューを開く処理
open: function() {
var _this = this;
_this.isOpen = true;
_this.$slideContentsWrap
.css('-webkit-transform', 'translate3d(-' + (_this.DISTANCE) + 'px, 0, 0)')
.removeClass('init')
.addClass('move');
clearTimeout(_this.timer);
_this.timer = setTimeout(function() {
_this.$slideMenu.css({ zIndex: '1' });
}, 200);
},
// スライドメニューを閉じる処理
close: function() {
var _this = this;
_this.isOpen = false;
_this.$slideMenu.css({ zIndex: '-1' });
_this.$slideContentsWrap
.css('-webkit-transform', 'translate3d(0, 0, 0)')
.removeClass('init')
.addClass('move');
},
// イベントキャンセル & 伝播
_cancelEvent: function() {
event.preventDefault();
event.stopPropagation();
},
// スライドメニューを開く
_slideMenuOpenClick: function() {
if (!this.isOpen) {
this._cancelEvent();
this.open();
this.isOpen = true;
}
else return;
},
// スライドメニューを閉じる
_slideMenuCloseClick: function() {
if (this.isOpen) {
this._cancelEvent();
this.close();
this.isOpen = false;
}
else return;
}
};
})(Zepto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment