项目作者: slavanga

项目描述 :
Lightweight but complete off-canvas solution.
高级语言: JavaScript
项目地址: git://github.com/slavanga/pusha.git
创建时间: 2017-05-04T20:14:18Z
项目社区:https://github.com/slavanga/pusha

开源协议:MIT License

下载


Pusha

Pusha is a lightweight but complete off-canvas solution.

Setup

  • Output panels before the pusha-wrapper
  • Use the pusha-push class on fixed elements (e.g. header)
  • Close events are bound to the first element with a data-close attribute inside a panel
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" href="dist/css/pusha.min.css" />
  5. </head>
  6. <body>
  7. <div class="pusha-panel pusha-panel--left" aria-hidden="true">
  8. <div class="pusha-panel__content">
  9. <p>Panel</p>
  10. <button data-close>Close Panel</button>
  11. </div>
  12. </div>
  13. <header class="header-fixed pusha-push">
  14. <p>Header</p>
  15. </header>
  16. <div class="pusha-wrapper">
  17. <p>Content</p>
  18. <button class="js-open-panel" aria-expanded="false">Open Panel</button>
  19. </div>
  20. <script src="dist/js/pusha.min.js"></script>
  21. <script>
  22. var panel = new Pusha('.pusha-panel--left');
  23. document.querySelector('.js-open-panel').addEventListener('click', panel.open);
  24. </script>
  25. </body>
  26. </html>

Styling (Using Sass)

Variables

  1. $pusha-z-index: 200;
  2. $pusha-duration: 0.3s;
  3. $pusha-easing: ease;
  4. $pusha-blocker-z-index: $pusha-z-index + 10;
  5. $pusha-blocker-duration: $pusha-duration;
  6. $pusha-blocker-bg: rgba(0, 0, 0, 0.5);
  7. $pusha-directions: (left, right, top, bottom);

Mixins

  1. .my-panel {
  2. @include pusha-panel(
  3. $direction: left, // left, right, top, bottom
  4. $mode: push, // push, pull, overlay, fade
  5. $width: 260px,
  6. $height: 100%,
  7. $background: #fff
  8. );
  9. }

Options

  1. new Pusha('.my-panel', {
  2. closeOnEsc: true,
  3. closeOnClick: true,
  4. disableOverscroll: true,
  5. disableBodyscroll: false,
  6. activeClass: 'pusha-active',
  7. onOpen: function(panel) {},
  8. onClose: function(panel) {}
  9. });

Note: Setting disableBodyscroll to true may lead to degraded scroll performance.

API

  1. var panel = new Pusha('.my-panel');
  2. // Public methods
  3. panel.open();
  4. panel.close();
  5. panel.toggle();
  6. // Public properties
  7. panel.isOpen;

Recipes

Scroll Panel to Top

  1. var panel = new Pusha('.my-panel', {
  2. onOpen: function(panel) {
  3. panel.children[0].scrollTop = 0;
  4. }
  5. });

License

The code is released under the MIT license.