GithubHelp home page GithubHelp logo

stereochrome / sidebarjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sidebarjs/sidebarjs

0.0 2.0 0.0 180 KB

Create mobile sidebar/sidenav experiance in pure javascript

License: MIT License

JavaScript 1.88% TypeScript 90.79% CSS 7.33%

sidebarjs's Introduction

GitHub release npm npm

SidebarJS

Create mobile sidebar/sidenav experiance in pure javascript.

npm install sidebarjs --save

Demo

Open the demo on your device and try the touch gestures!

Libraries

Import

Typescript

import {SidebarElement, SidebarService} from 'sidebarjs';

ES6

import {SidebarElement, SidebarService} from 'sidebarjs';

Require

const {SidebarElement, SidebarService} = require('sidebarjs');

Classic

<script src="your/path/sidebarjs.js"></script>

Options

const sidebarjs = new SidebarElement({
    component?: HTMLElement['sidebarjs'], // Sidebar DOM element
    documentMinSwipeX?: 10, // Minimum swipe in px required to trigger listener: open
    documentSwipeRange?: 40, // Range in px where document is listening for gesture: open
    nativeSwipe?: true, // Open and close sidebar with swipe gestures
    nativeSwipeOpen?: true, // Enable/Disable open on swipe
    position?: 'left', // Sidebar position, accepted values: left|right
})

Single Sidebar

<head>

  <link rel="stylesheet" href="sidebarjs.min.css">

</head>
<body>

  <div sidebarjs-toggle>Open/Close</div>

  <div sidebarjs>
    <nav>
      <a href="link">Home</a>
      <a href="link">About</a>
      <a href="link">Contacts</a>
    </nav>
  </div>

  <script src="sidebarjs.min.js"></script>
  <script>
  // Init SidebarJS
  var sidebarjs = new SidebarJS.SidebarElement();
  </script>

</body>

Multiple Sidebars

<head>

  <link rel="stylesheet" href="sidebarjs.min.css">

</head>
<body>

  <div sidebarjs-toggle="leftSidebarName">Open/Close Left Sidebar</div>
  <div sidebarjs-toggle="rightSidebarName">Open/Close Right Sidebar</div>

  <div sidebarjs="leftSidebarName">
    <nav>
      <a href="link">My</a>
      <a href="link">Left</a>
      <a href="link">Content</a>
    </nav>
  </div>

  <div sidebarjs="rightSidebarName">
    <nav>
      <a href="link">My</a>
      <a href="link">Right</a>
      <a href="link">Content</a>
    </nav>
  </div>

  <script src="sidebarjs.min.js"></script>
  <script>
  var leftSidebarjs = new SidebarJS.SidebarElement({
    component: document.querySelector('[sidebarjs="leftSidebarName"]'),
  });
  
  var rightSidebarjs = new SidebarJS.SidebarElement({
    component: document.querySelector('[sidebarjs="rightSidebarName"]'),
    position: 'right',
  });
  </script>

</body>

Implementation step by step

Download files

Download and save all files

$ npm install sidebarjs --save

Insert sidebarjs.min.css and sidebarjs.min.js in your index.html.

<head>

  <link rel="stylesheet" href="your/path/sidebarjs.min.css">

</head>
<body>

  <script src="your/path/sidebarjs.min.js"></script>

</body>

Create SidebarJS element

Write [sidebarjs] attribute inside a tag (div, aside, or whatever you want).

<div sidebarjs>
  <div>Title</div>
  <nav>
    <a href="link">Home</a>
    <a href="link">About</a>
    <a href="link">Contacts</a>
  </nav>
</div>

Trigger button

Do you need a trigger button for open/close SidebarJS? Just put [sidebarjs-toggle] attribute inside a tag and it's done!

<div sidebarjs-toggle>Open/Close</div>

Init

When you have files, [sidebarjs] and [sidebarjs-toggle] you can init your SidebarJS Module like:

const sidebarjs = new SidebarJS.SidebarElement()

Full file example

<head>

  <link rel="stylesheet" href="your/path/sidebarjs.min.css">

</head>
<body>

  <div sidebarjs-toggle>Open/Close</div>

  <div sidebarjs>
    <div>Title</div>
    <nav>
      <a href="link">Home</a>
      <a href="link">About</a>
      <a href="link">Contacts</a>
    </nav>
  </div>

  <script src="your/path/sidebarjs.min.js"></script>
  <script>
    // Init SidebarJS
    const sidebarjs = new SidebarJS.SidebarElement();
  </script>

</body>

sidebarjs's People

Contributors

lorenzodianni avatar

Watchers

 avatar James Cloos avatar

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.