├── .eslintrc.json
├── .gitignore
├── .jshintrc
├── .travis.yml
├── LICENSE
├── README.md
├── dist
├── jquery.offcanvas.min.css
└── jquery.offcanvas.min.js
├── docs
├── demo
│ ├── advanced.html
│ └── index.html
├── index.html
└── styles.css
├── gulpfile.js
├── package.json
├── src
├── jquery.offcanvas.css
└── jquery.offcanvas.js
└── test
├── plugin.js
├── runner.html
└── vendor
├── jquery-1.11.3.min.js
└── velocity.min.js
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "airbnb/legacy",
3 | "rules": {
4 | "func-names": 0,
5 | "no-shadow": 0,
6 | "no-param-reassign": 0,
7 | "no-var": 0,
8 | "object-shorthand": 0,
9 | "no-console": 0,
10 | "strict": 0
11 | },
12 | "globals": {
13 | "define": false,
14 | "jQuery": false
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # node-waf configuration
20 | .lock-wscript
21 |
22 | # Compiled binary addons (http://nodejs.org/api/addons.html)
23 | build/Release
24 |
25 | # Dependency directory
26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27 | node_modules
28 |
29 | .DS_Store
30 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "esnext": true
3 | }
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "stable"
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Lars Graubner
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jQuery.offcanvas
2 |
3 | [](https://travis-ci.org/lgraubner/jquery-offcanvas) [](https://david-dm.org/lgraubner/jquery-offcanvas#info=devDependencies) [](https://www.npmjs.com/package/jquery-offcanvas)
4 |
5 | > An easy to use jQuery offcanvas plugin.
6 |
7 | This plugin provides an easy way to put content outside of the canvas and reveal it with a click on a button or any desired element. This is a useful pattern for mobile navigations and more.
8 |
9 | [Demo](http://lgraubner.github.io/jquery-offcanvas/demo/) | [Download](https://github.com/lgraubner/jquery-offcanvas/releases/latest)
10 |
11 | ## Dependencies
12 |
13 | As this is a jQuery plugin it depends on the [jQuery library](http://jquery.com/) v1.7+. For smooth animations [Velocity.js](https://github.com/julianshapiro/velocity) is used. Both dependencies are required.
14 |
15 | ## Usage
16 |
17 | You can install this module either with npm or download it manually. Include jQuery, Velocity.js and the plugin before the closing `body` tag:
18 |
19 | ```HTML
20 |
21 |
22 |
23 | ```
24 |
25 | Include the CSS file:
26 |
27 | ```HTML
28 |
29 | ```
30 |
31 | If you are not using npm just adjust the paths to match the file locations.
32 |
33 | It's not required to have any specific markup. The plugin handles any positioning itself. The only requirement is a wrapping element around the offcanvas contents.
34 |
35 | ### Initialization
36 |
37 | ```JavaScript
38 | var $el = $("#element").offcanvas();
39 |
40 | $(".offcanvas-trigger").on("click", function() {
41 | $el.offcanvas("toggle");
42 | });
43 | ```
44 |
45 | Clicks on the trigger element will toggle the offcanvas element.
46 |
47 | **Do not try to initialize more than one instance of jQuery.offcanvas on one page!**
48 |
49 | ## Options
50 |
51 | Options can be set on initialization:
52 |
53 | ```JavaScript
54 | $("#element").offcanvas({
55 | origin: "right",
56 | duration: 400
57 | });
58 | ```
59 |
60 | You can also set options via data-Attributes, which will overwrite the default value and the value specified on initialization:
61 |
62 | ```HTML
63 |
64 | ...
65 |
66 | ```
67 |
68 | ### classes
69 |
70 | Type: `object`
71 | Default:
72 | ```JavaScript
73 | {
74 | container: "offcanvas",
75 | element: "offcanvas-element",
76 | inner: "offcanvas-inner",
77 | open: "offcanvas-open",
78 | outer: "offcanvas-outer",
79 | overlay: "offcanvas-overlay"
80 | }
81 | ```
82 |
83 | Classes which will be applied to the elements.
84 |
85 | **If you change class names make sure to update them in the CSS file accordingly.**
86 |
87 | ### container
88 |
89 | Type: `String`
90 | Default: `body`
91 |
92 | Page container, which will be animated. Expects a jQuery selector.
93 |
94 | ### coverage
95 |
96 | Type: `String`
97 | Default: `220px`
98 |
99 | Width of the offcanvas element which will be revealed.
100 |
101 | **Tip:** For better performance avoid using % values.
102 |
103 | ### duration
104 |
105 | Type: `number`
106 | Default: `300`
107 |
108 | Duration of the animation.
109 |
110 | ### easing
111 |
112 | Type: `String`
113 | Default: `ease-in-out`
114 |
115 | Easing type for show and hide animations. You can use:
116 |
117 | - [jQuery UI's easings](http://easings.net/de)
118 | - CSS3's named easings: `ease`, `ease-in`, `ease-out`, and `ease-in-out`
119 |
120 | For more easing options check the [Velocity.js documentation](http://julian.com/research/velocity/#easing).
121 |
122 | ### effect
123 |
124 | Type: `String`
125 | Default: `push`
126 |
127 | Effect used to transition the offcanvas element into the viewport. Possible values are `push` and `slide-in-over`. Check the [demos](http://lgraubner.github.io/jquery-offcanvas/demo/) for an impression of the effects.
128 |
129 | ### origin
130 |
131 | Type: `String`
132 | Default: `left`
133 |
134 | Direction the offcanvas element is revealed from. Possible values are `left` and `right`.
135 |
136 | ### overlay
137 |
138 | Type: `boolean`
139 | Default: `false`
140 |
141 | Adds an overlay to cover the content of the page. A click anywhere on the overlay will hide the offcanvas.
142 |
143 | ### overlayColor
144 |
145 | Type: `String`
146 | Default: `rgba(0, 0, 0, 0.7)`
147 |
148 | Color of the overlay element. Best suited are `rgba` values to add a decent looking transparency. You can use `rgba(0, 0, 0, 0.7)` as starting point to play around. The overlay will be smoothly transitioned into the view.
149 |
150 | ## API
151 |
152 | The offcanvas API offers a couple of methods to control the offcanvas element. The methods are called like this:
153 |
154 | ```JavaScript
155 | $("#element").offcanvas("show");
156 | ```
157 |
158 | ### show
159 |
160 | Shows the offcanvas element.
161 |
162 | ### hide
163 |
164 | Hides the offcanvas element.
165 |
166 | ### toggle
167 |
168 | Toggles the offcanvas element.
169 |
170 | ### destroy
171 |
172 | Destroys the jQuery.offcanvas instance and reverts all DOM changes.
173 |
174 | ## Events
175 |
176 | jQuery.offcanvas fires several events. Simply listen for them with the `jQuery.on` function. All events are namespaced with `offcanvas`.
177 |
178 | ```JavaScript
179 | $("#element").on("shown.offcanvas", function() {
180 | // do stuff when offcanvas is revealed and animation is finished
181 | });
182 | ```
183 |
184 | ### init
185 |
186 | Fired once the Plugin is initialized.
187 |
188 | ### show
189 |
190 | Fired when the `show` method is called.
191 |
192 | ### shown
193 |
194 | Fired when the `show` animation finished.
195 |
196 | ### hide
197 |
198 | Fired when the `hide` method is called.
199 |
200 | ### toggle
201 |
202 | Fired when the offcanvas gets toggled. Gets fired on both, `show` and `hide` methods. The second function argument contains the offcanvas state as `boolean`.
203 |
204 | ```JavaScript
205 | $("#element").on("toggle.offcanvas", function(event, visible) {
206 | console.log(visible) // outputs offcanvas state (true or false)
207 | });
208 | ```
209 |
210 | ### hidden
211 |
212 | Fired when the `hide` animation finished.
213 |
--------------------------------------------------------------------------------
/dist/jquery.offcanvas.min.css:
--------------------------------------------------------------------------------
1 | /**
2 | * jQuery.offcanvas v3.4.7 - Easy to use jQuery offcanvas plugin.
3 | * Copyright 2016 Lars Graubner - http://lgraubner.github.io/jquery-offcanvas/
4 | * License: MIT
5 | */
6 | .offcanvas{position:relative}.offcanvas-outer{left:0;overflow-x:hidden;position:absolute;top:0;width:100%}.offcanvas-inner{position:relative}.offcanvas-element{margin:0;overflow:hidden;position:absolute;top:0;z-index:2}.offcanvas-overlay{display:none;position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;z-index:1}
--------------------------------------------------------------------------------
/dist/jquery.offcanvas.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | * jQuery.offcanvas v3.4.7 - Easy to use jQuery offcanvas plugin.
3 | * Copyright 2016 Lars Graubner - http://lgraubner.github.io/jquery-offcanvas/
4 | * License: MIT
5 | */
6 | !function(t,e){"object"==typeof module&&"object"==typeof module.exports?module.exports=function(t,s){return void 0===s&&(s="undefined"!=typeof window?require("jquery"):require("jquery")(t)),e(s),s}:"function"==typeof define&&define.amd?define(["jquery "],e):e(jQuery)}(this,function(t){"use strict";function e(t,e,s){var i;return function(){var n=this,o=arguments,h=function(){i=null,s||t.apply(n,o)},a=s&&!i;clearTimeout(i),i=setTimeout(h,e),a&&t.apply(n,o)}}function s(e,s){var n,o,h=t(e).data();this.$el=t(e);for(n in h)h.hasOwnProperty(n)&&/^offcanvas[A-Z]+/.test(n)&&(o=n[i.length].toLowerCase()+n.substr(i.length+1),h[o]=h[n]);this.settings=t.extend(!0,{},t.fn[i].defaults,s,h),this.name=i,this.$el.data(this.name+".opts",this.settings),this.init()}var i="offcanvas";t.extend(s.prototype,{setHeights:function(){var t=this.$outerWrapper.height();this.$el.data(this.name+".opts")&&(this.$element.css("height",t),this.settings.overlay&&this.$overlay.css("height",t))},show:function(){var e={};this.visible||(this.$cont.addClass(this.settings.classes.open),this.visible=!0,this.$el.trigger("show."+this.name),this.$el.trigger("toggle."+this.name,this.visible),this.setHeights(),e[this.settings.origin]=this.effects[this.settings.effect].to,this.effects[this.settings.effect].$el.velocity(e,t.extend({complete:function(){this.$el.trigger("shown."+this.name),this.settings.overlay&&this.$overlay.one("click."+this.name,function(){this.hide()}.bind(this))}.bind(this)},this.animationOptions)),this.settings.overlay&&this.$overlay.velocity({opacity:1},t.extend({display:"block"},this.animationOptions)))},hide:function(){this.visible&&(this.$cont.removeClass(this.settings.classes.open),this.visible=!1,this.$el.trigger("hide."+this.name),this.$el.trigger("toggle."+this.name,this.visible),this.effects[this.settings.effect].$el.velocity("stop").velocity("reverse",t.extend({complete:function(){this.$el.trigger("hidden."+this.name)}.bind(this)},this.animationOptions)),this.settings.overlay&&this.$overlay.velocity("stop").velocity("reverse",t.extend({display:"none"},this.animationOptions)))},toggle:function(){return(this.visible?this.hide:this.show).call(this)},destroy:function(){this.$el.data(this.name+".opts")&&(this.$innerWrapper.unwrap(),this.$innerWrapper.children().unwrap(),this.$cont.removeClass(this.settings.classes.container).removeClass(this.settings.classes.open),this.settings.overlay&&this.$overlay.off("click."+this.name).remove(),this.$el.unwrap().removeData(this.name+".opts").removeAttr("style"),this.$win.off("resize."+this.name))},init:function(){var s={};this.$win=t(window),this.$body=t("body"),this.visible=!1,this.$cont=t(this.settings.container),this.$cont.addClass(this.settings.classes.container).children(":not(script)").wrapAll(t("").addClass(this.settings.classes.outer)),this.$outerWrapper=t("."+this.settings.classes.outer).wrapInner(t("").addClass(this.settings.classes.inner)),this.$innerWrapper=t("."+this.settings.classes.inner),this.settings.overlay&&(this.$innerWrapper.append(t("").addClass(this.settings.classes.overlay).css("background-color",this.settings.overlayColor)),this.$overlay=t("."+this.settings.classes.overlay)),this.$el.wrap(t("").addClass(this.settings.classes.element)),this.$element=this.$el.parent(),s[this.settings.origin]="-"+this.settings.coverage,s.width=this.settings.coverage,this.$element.css(s),this.effects={push:{$el:this.$innerWrapper,from:0,to:this.settings.coverage},"slide-in-over":{$el:this.$element,from:"-"+this.settings.coverage,to:0}},this.animationOptions={easing:this.settings.easing,duration:this.settings.duration},this.$win.on("resize."+this.name,e(this.setHeights,300).bind(this)),this.setHeights(),this.$el.trigger("init."+this.name)}}),t.fn[i]=function(e){var n,o=arguments;return void 0===e||"object"==typeof e?this.each(function(){t.data(this,"plugin_"+i)||t.data(this,"plugin_"+i,new s(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e&&(this.each(function(){var h=t.data(this,"plugin_"+i);h instanceof s&&"function"==typeof h[e]&&(n=h[e].apply(h,Array.prototype.slice.call(o,1))),"destroy"===e&&t.data(this,"plugin_"+i,null)}),void 0!==n?n:this)},t.fn[i].defaults={classes:{container:i,element:i+"-element",inner:i+"-inner",open:i+"-open",outer:i+"-outer",overlay:i+"-overlay"},container:"body",coverage:"220px",origin:"left",duration:300,easing:"ease-in-out",effect:"push",overlay:!1,overlayColor:"rgba(0, 0, 0, 0.7)"}});
--------------------------------------------------------------------------------
/docs/demo/advanced.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Advanced Demo - jQuery.offcanvas Plugin - Lars Graubner
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
jQuery.offcanvas
40 |
Advanced Demo
41 |
42 |
Alternate effect to transition offcanvas into viewport, revealed from the right and colored overlay.
This plugin provides an easy way to put content outside of the canvas and reveal it with a click on a button or any desired element. This is a useful pattern for mobile navigations and more.
It's not required to have any specific markup. The plugin handles any positioning itself. The only requirement is a wrapping element around the offcanvas contents.
Overlay content of the container when offcanvas is visible.
147 |
148 |
CSS selector for the trigger button.
149 |
150 |
effect
151 |
152 |
Type: String
153 | Default: push
154 |
155 |
Effect used to transition the offcanvas element into the viewport. Possible values are push and slide-in-over. Check the demos for an impression of the effects.
156 |
157 |
origin
158 |
159 |
Type: String
160 | Default: left
161 |
162 |
Direction the offcanvas is revealed from. Possible values are left and right.
163 |
164 |
overlay
165 |
166 |
Type: boolean
167 | Default: false
168 |
169 |
Adds an overlay to cover the content of the page. A click anywhere on the overlay will hide the offcanvas.
170 |
171 |
overlayColor
172 |
173 |
Type: String
174 | Default: rgba(0, 0, 0, 0.7)
175 |
176 |
Color of the overlay element. Best suited are rgba values to add a decent looking transparency. You can use rgba(0, 0, 0, 0.7) as starting point to play around. The overlay will be smoothly transitioned into the view.
177 |
178 |
API
179 |
180 |
The offcanvas API offers a couple of methods to control the offcanvas. The methods are called like this:
181 |
182 |
$("#element").offcanvas("show");
183 |
184 |
show
185 |
186 |
Shows the offcanvas element.
187 |
188 |
hide
189 |
190 |
Hides the offcanvas element.
191 |
192 |
toggle
193 |
194 |
Toggles the offcanvas element.
195 |
196 |
destroy
197 |
198 |
Destroys the jQuery.offcanvas instance and reverts all DOM changes.
199 |
200 |
Events
201 |
202 |
jQuery.offcanvas fires several events. Simply listen for them with the jQuery.on function. All events are namespaced with offcanvas.
203 |
204 |
$("#element").on("shown.offcanvas", function() {
205 | // do stuff when offcanvas is revealed and animation is finished
206 | });
207 |
208 |
init
209 |
210 |
Fired once the Plugin is initialized.
211 |
212 |
show
213 |
214 |
Fired when the show method is called.
215 |
216 |
shown
217 |
218 |
Fired when the show animation finished.
219 |
220 |
hide
221 |
222 |
Fired when the hide method is called.
223 |
224 |
toggle
225 |
226 |
Fired when the offcanvas gets toggled. Gets fired on both, show and hide methods. The second function argument contains the offcanvas state as boolean.
227 |
228 |
$("#element").on("toggle.offcanvas", function(event, visible) {
229 | console.log(visible) // outputs offcanvas state (true or false)
230 | });