Code Monkey home page Code Monkey logo

superslide.js's Introduction

SuperSlide.js

A lightweight, configurable sliding menu for your next PWA with promises. Only 2k gzipped!

This library aims to provide a highly configurable, ready-to-use sliding menu for your next web application, while delivering native-like animation performance. It was created by the OSREC Technologies while developing Bx, our invoicing, time-tracking and project management PWA.

Installation

npm install superslide.js

Usage

Reference the library in a script tag

<script src='superslide.js'></script>

Add basic HTML markup

<body>
  <div id='content'>Content</div>
  <div id='menu'>Menu</div>
</body>

Add styles (so we can see what's going on!)

<style>
  body     { padding: 0px; margin: 0px; }
  #menu    { background: #ccc; }
  #content { min-height: 100vh; min-width: 100vw; }
</style>

Initialise the menu

var myMenu = new OSREC.superslide
({
    slider: document.getElementById('menu'),
    content: document.getElementById('content'),
    animation: 'slideLeft'
});

// Promise resolves once menu is open
var openPromise = myMenu.open();

Try the demo here

Animations

Standard Version has 4 animation options available:

slideLeft slideRight slideBottom slideTop

PRO version โญ contains many more menu animations (check it out @ https://osrec.co.uk/products/superslidejs)

Parameters

  • animation (string): Any of the animations in the animation library (slideLeft, slideRight, slideTop, slideBottom).

  • duration (integer): Duration in seconds for the slide animation

  • allowDrag (boolean): Allow the menu to be dragged into the open or closed position via touch events.

  • slideContent (boolean): Slide the content along with the menu

  • allowContentInteraction (boolean): Allow the content to be clicked or scrolled while the menu is open

  • closeOnBlur (boolean): Close the menu when the user clicks or taps anywhere outside the menu

  • width (string): The width of the menu (for menus that sit along a vertical edge). Examples: '60vw' or '300px' or '80%'

  • height (string): The height of the menu (for menus that sit along a horizontal edge). Examples: '50vh' or '300px' or '80%'

  • dragThreshold (integer): The number of pixels from the edge from where a user can begin dragging; example: 70. Use with the allowDrag option.

  • openThreshold (integer): When the menu is in the open position, the number of pixels it must be dragged before it opens automatically; example: 30. Use with the allowDrag option.

  • closeThreshold (integer): When the menu is in the closed position, the number of pixels it must be dragged before it closes automatically; example: 20. Use with the allowDrag option.

  • beforeOpen (callback): Executed before the menu begins to open

  • onOpen (callback): Executed straight after the menu has opened

  • beforeClose (callback): Executed before the menu begins to close

  • onClose (callback): Executed as soon as the menu has closed

Methods

  • OSREC.superslide.open() Open the menu. Returns a promise that resolves once the menu opens (i.e. animation completes).

  • OSREC.superslide.close() Close the menu. Returns a promise that resolves once the menu closes (i.e. animation completes).

  • OSREC.superslide.toggle() Toggles the menu. Returns a promise that resolves once the menu has been toggled (i.e. animation completes).

  • OSREC.superslide.isOpen() True if the menu is open, false if closed. The last state if mid-drag. Returns a boolean.

  • OSREC.superslide.ready() Check if the menu is fully initialised. Returns a promise that resolves when fully initialised.

  • OSREC.superslide.destroy() Destroy the menu. This will close the menu if it is open before destroying. Returns null

Credits

Created by the Bx team at OSREC Technologies.

Bx

The library was developed as part of our business and project management app called Bx (you can check it out here).

superslide.js's People

Contributors

osrec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

superslide.js's Issues

Add "overlay" option

On most Andorid and iOS apps, when you open a menu, the viewport gets covered by a black overlay at 50% opacity. As you swipe, the overlay starts at 0% opacity, and as the menu opens, it fades to 50% opacity when the menu is fully open.

I could add an overlay the gets enabled on open or close, but I don't think your APIs let me add this kind of variable opacity overlay myself.

Add script for compressing JS

I've found the following seems to work well for me for this script:

uglifyjs superslide-std.js -c -m -o superslide-std.min.js

TypeError: superslide_js__WEBPACK_IMPORTED_MODULE_0___default.a.superslide is not a constructor

This looks awesome, and I'm trying to add it to my personal framework, but I'm running in to an odd issue that I can't seem to track down. I keep getting the error in the title, not sure what I'm doing wrong. I'm using webpack, initializing the script with:

import OSREC from "superslide.js";

const MOBILE_MENU = new OSREC.superslide({
    animation: "slideLeft",
    content:   document.getElementById("page-container"),
    slider:    document.getElementById("mobile-menu"),
});

#page-container and #mobile-menu both exist, and console.log(OSREC) outputs function superslide(), so I don't see what could be the problem. The only difference I'm seeing between my code and your example code is that I'm importing OSREC rather than including the script on the page.

Any help figuring out why this won't work would be appreciated.

Don't require `content` property if `slideContent` is false

If someone sets slideContent to false, the content property should not be a required parameter, since SuperSlide isn't interacting with the content in that circumstance.

Currently if slideContent is false, and no content is set, an error occurs in the console.

desktop fix left

Is there an option by which if it is desktop the menus will be fixed on the left (or the given position)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.