Git Product home page Git Product logo

swipeme's Introduction

#SwipeMe# ###A lightweight Javascript library for swiping open/close off-canvas menus###

SwipeMe is a Javascript library built to swipe open/close off-canvas navigation menus – currently relying on CSS3 animations. When a swipe is detected, SwipeMe will add (or remove) the appropriate CSS class from a main 'container' element. For an in-depth example of how to implement an off-canvas navigation pattern, see this brilliant example by Jason Weaver.

##Implementation##

Simply set up your CSS rules and pass SwipeMe the element that contains each of your panels:

###HTML###

<div id="swipeme">
    <div class="panel off-canvas-left">Left off-canvas</div>
    <div class="panel main-content">Main content</div>
    <div class="panel off-canvas-right">Right off-canvas</div>
</div>

###CSS###

/* Base styles */
.panel {
	float: left;
	transition: margin 0.4s ease-out;
}

.off-canvas-left {
	width: 85%;
	margin-left: -100%;
}

.main-content {
	width: 100%;
	margin-left: 0;
}

.off-canvas-right {
	margin-right: -200%;
	width: 85%;
}

/* Access left menu */
.access-left .off-canvas-left	{ margin-left: 0;		}
.access-left .main-content		{ margin-right: -100%;	}
.access-left .off-canvas-right	{ margin-left: 100%;	}

/* Access right menu */
.access-right .off-canvas-left	{ margin-left: -100%;	}
.access-right .main-content		{ margin-left: -85%;	}
.access-right .off-canvas-right	{ margin-left: 0;		}

###JavaScript###

var swipe = new SwipeMe(document.getElementById('swipeme'));

##Customisation## ###Options###

var swipe = new SwipeMe(
	document.getElementById('swipeme'),
	{
	    accessClasses: {
	        left: 'access-left',
	        right: 'access-right'
	    },
	    direction: ['left', 'right']
	}
);
  • accessClasses: An object containing the classes that will be applied to the container when a swipe has occurred
  • direction: An array of available directions, useful for specifying if you only have a menu on one side. Also accepts a string.

###Disabling SwipeMe on certain elements### You may wish to prevent SwipeMe from triggering a swipe event when touching certain elements on a page – a common example being an image carousel. Simply add a data-swipeme-ignore="true" attribute to prevent swipe events being triggered when the element, or any of its child elements, are touched.

##Caveats## ###Browser Support### As the library currently only adds and removes CSS classes, all animations are CSS-generated – so <=IE9 and Opera Mini won't get any animations. Ancient versions of IE (<IE9) will need to use the swipeme.ltie9.js plugin to provide Array.indexOf() and String.trim() support.

###Windows Phone### Currently not supported as it doesn't support touchstart/touchmove/touchend events. Need to delve deeper into MSPointerEvents etc. A pull request for support would be gratefully accepted.

###iOS 7### iOS 7 adds swipe navigation gestures to Safari, which (as far as I'm aware) can't be disabled. It's still possible to use this library with iOS 7 – the native gestures are only triggered when swiping from the very edge of the page.

##TODO##

  • Further device testing. Tested so far on:
    • iOS 5
    • iOS 6
    • iOS 7
    • Android 4.x
  • Windows Phone support

swipeme's People

Contributors

kinglozzer avatar bendroid avatar feejin avatar

Watchers

 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.