• Stars
    star
    1,297
  • Rank 35,358 (Top 0.8 %)
  • Language
    JavaScript
  • Created over 12 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

👟 Pep, a lightweight plugin for kinetic drag on mobile/desktop

jquery.pep.js

Kinetic drag for mobile & desktop.

Demos and more at http://pep.briangonzalez.org.

Installation

NPM (recommended)

npm install jquery.pep.js --save

Bower

bower install jquery.pep

Getting Started

Getting started is simple: include jQuery, include pep, then:

$('.pep').pep(); // yup, that simple.

Usage

Pep has many options. Here they are in their entirety, with their defaults. Need a little help? Just ask.

Name Default Description
initiate function(){} [≘ touchstart/mousedown] called when first touch / click event is triggered on the object
start function(){} called when dragging starts; when dx or dy are greater than startThreshold[0] or startThreshold[1]
drag function(){} [≘ touchmove/mousemove] called continuously while the object is dragging
stop function(){} [≘ touchend/mouseup] called when dragging stops
easing function(){} called while object is easing
rest function(){} called after dragging stops, and object has come to rest
moveTo false custom method to override the default moveTo functionality.
callIfNotStarted ['stop', 'rest'] if object has not moved outside of the startThreshold, call either the user-provided stop or rest fxn's anyway, or call both
startThreshold [0,0] how far past should the object move in the [x,y] direction before user 'start' function is called
grid [0,0] define an [x,y] grid for the object to move along
revert false revert back to initial position
revertAfter stop revert after given event - 'stop' or 'ease'
revertIf function(){ return true; } return false / true from this function to conditionally revert an object
droppable false CSS selector that this element can be dropped on, false to disable
droppableActiveClass 'pep-dpa' class to add to active droppable parents, default to pep-dpa (droppable parent active); inspect this.activeDropRegions within each function for valuable info
overlapFunction false override pep's default overlap function; takes two args: a & b and returns true if they overlap
cssEaseString cubic-bezier(0.190, 1.000, 0.220, 1.000) get more css ease params from [ http://matthewlein.com/ceaser/ ]
cssEaseDuration 750 how long should it take (in ms) for the object to get from stop to rest?
constrainTo false constrain object to 'window' or 'parent' or [top, right, bottom, left]; works best w/ useCSSTranslation set to false
axis null constrain object to either 'x' or 'y' axis. Set to 'auto' to constrain to either the x or the y axis automatically, depending on the direction in which the user is dragging
debug false show debug values and events in the lower-righthand corner of page
activeClass 'pep-active' class to add to the pep element while dragging
startClass 'pep-start' class to add to the pep element when dragging starts. (If a startThreshold option is defined then this class is added only after dragging past the threshold.)
easeClass 'pep-ease' class to add to the pep element while easing
multiplier 1 +/- this number to modify to 1:1 ratio of finger/mouse movement to el movement
velocityMultiplier 1.9 +/- this number to modify the springiness of the object as your release it
shouldPreventDefault true in some cases, we don't want to prevent the default mousedown/touchstart on our Pep object, your call
allowDragEventPropagation true set to false to stop drag events from bubbling up through the DOM tree
stopEvents '' space delimited set of events which programmatically cause the object to stop
hardwareAccelerate true apply the CSS3 silver bullet method to accelerate the pep object: http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
useCSSTranslation true use CSS transform translations as opposed to top/left
disableSelect true apply user-select: none (CSS) to the object
removeMargins true remove margins for better object placement
shouldEase true disable/enable easing
place true bypass pep's object placement logic
deferPlacement false defer object placement until start event occurs
forceNonCSS3Movement false DO NOT USE: this is subject to come/go. Use at your own risk
elementsWithInteraction 'input' valid CSS/jQuery selector for elements within the Pep object that should allow user interaction, and thus propagate to allow movement
ignoreRightClick true start event will be ignored if triggered by a right click
startPos { left: null, top: null } set the default left/top coordinate to position the object with on load
useBoundingClientRect false use getBoundingClientRect() to retrieve element dimensions instead of jQuery's .outerWidth() & .outerHeight() (useful when your element is scaled via CSS transforms)

API

// Toggle functionality of all Pep objects on the page
$.pep.toggleAll()

// Explicitly disable all Pep objects on the page
$.pep.toggleAll(false)

// Explicitly enable all Pep objects on the page
$.pep.toggleAll(true)

// Unbind Pep completely from the object
var $pep = $('.pep');
$pep.pep();               // bind
$.pep.unbind( $pep );     // unbind
$pep.pep();               // bind

Class applications

The following classes are applied corresponding to events that are happening on the pep object:

  • pep-active -- applied when initiate event is triggered; removed when ease has finished
  • pep-start -- applied when start event is triggered; removed when stop event occurs
  • pep-ease -- applied when stop event is triggered; removed when ease has finished

A note on droppable option

There is a convenience object within the context of each function pep makes available (drag, rest, ease, etc.) called activeDropRegions, which is an array of jQuery objects that the pep object is currently "over".

Example:

$('.pep').pep({
  droppable:   '.drop-target',
  drag: function(ev, obj){
    console.log('There are ' + this.activeDropRegions.length + 'active drop regions.')
  },
  revert: true,
  revertIf: function(ev, obj){
    return !this.activeDropRegions.length;
  }
})

Author

twitter/brianmgonzalez
Brian Gonzalez

Support

Pep includes at least partial support for most browsers, dating back to IE6.

License

Pep is licensed under the MIT License

More Repositories

1

jquery.adaptive-backgrounds.js

🦎 A jQuery plugin for extracting the dominant color from images and applying the color to their parent.
JavaScript
6,553
star
2

rgbaster.js

🎨 A simple library for extracting dominant colors from images.
TypeScript
1,736
star
3

fontprep

🔣 The missing font generator for Mac OSX.
JavaScript
1,232
star
4

jquery.arbitrary-anchor.js

âš“ Arbitrary anchors for any element on your page using a little jQuery magic.
JavaScript
370
star
5

codrops-medium-style-page-transitions

The repository for this article: http://tympanus.net/codrops/2013/10/30/medium-style-page-transition/
CSS
257
star
6

termrc

Take your iTerm2 environments with you wherever you go.
Ruby
88
star
7

cocoa-rack

Run rack apps within Mac apps.
Objective-C
87
star
8

alfred-messages

Message your Apple Contacts via Alfred using Messages
Swift
66
star
9

awesome-applescripts

A collection of awesome, useful, not-so-obvious applescripts.
AppleScript
63
star
10

craigslist-scout

A dead simple command line tool to query multiple Craigslist cities (subdomains) and email out new results.
JavaScript
19
star
11

gridss

A CSS Grid microlib.
HTML
15
star
12

calle-app

CalleApp: El ultimo SF food truck locator.
JavaScript
12
star
13

gulp-file-contents-to-json

Slurp in some files, output a JSON representation of their contents.
JavaScript
12
star
14

nesta-boilerplate

Nesta starting point with baked-in H5BP, Compass, Semantic GS, & Capistrano
JavaScript
11
star
15

border-animate.js

Effortless border-length animations.
JavaScript
11
star
16

google-drive-email-saver

google-drive-email-saver
Ruby
10
star
17

broccoli-file-contents-to-json

Given a directory of files, output a JSON representation of their contents.
JavaScript
9
star
18

inkpress

A small, lightweight, dead simple content management system built on free & open source technologies.
JavaScript
8
star
19

top

Top: OSX App to emulate iOS's scroll-to-top functionality
Objective-C
6
star
20

alfred-reminders

View, add, and complete reminders via Alfred.
JavaScript
6
star
21

briangonzalez.org

My website built atop Hexo, VueJS, and Github Pages.
CSS
6
star
22

Sirkel

Geolocation-based chat app
JavaScript
5
star
23

cleardns

Dependency-free, platform-aware, DNS-clearing library.
JavaScript
5
star
24

animicons

Animicons: Sprite Animations with Icon Fonts
4
star
25

reminders-menu-bar

Reminders in your menu bar.
JavaScript
4
star
26

alfred-cleardns

Clear your DNS via Alfred.
JavaScript
4
star
27

dotfile-cabinet

Responsibly manage your dotfiles with Dropbox.
Ruby
4
star
28

eotlitetool.py

Create EOT version of OpenType font for use with IE
Python
3
star
29

fontprep-crx

A Chrome extension for FontPrep.
JavaScript
3
star
30

auth-code-copy

Copy auth codes sent via iMessage to your clipboard.
JavaScript
3
star
31

jquery.pep.js-website

jquery.pep.js website (built on Sinatra)
JavaScript
2
star
32

compass2css

Convert Compass to CSS. On the web.
Ruby
2
star
33

poly-cms-gem

A simple way to manage your content.
Ruby
2
star
34

ember-polymorphic

Polymorphic relationship example in Ember.
JavaScript
2
star
35

grunt-starter

A simple grunt starter project.
JavaScript
2
star
36

underscore-template-fetcher

A small utility function built on top of underscore.js which provides a simple API for fetching template strings via AJAX.
JavaScript
2
star
37

sinatra-webdav-neue

A Sinatra-based webdav server powered by rack_dav.
Ruby
2
star
38

origin

a simple sinatra starter
JavaScript
2
star
39

async-await-import-export

Passing around async functions.
JavaScript
1
star
40

code-copy

A macOS for copying auth codes sent via iMessage.
TypeScript
1
star
41

stub-stub

A node module for quick and dirty API stubbing based on YAML files inside a sensible directory structure.
JavaScript
1
star
42

farkle-ai

A Sinatra interface to a Monte Carlo-based Farkle AI.
Ruby
1
star
43

ts-export-import-demo

TypeScript
1
star
44

alfred-table

Paste a random table flip to your clipboard ┬──┬ ノ( ゜-゜ノ)
JavaScript
1
star
45

blog-compile-handlebars-templates-ember-with-gulp

Compile Handlebars templates for Ember with Gulp.
JavaScript
1
star