TouchSwipe-Jquery-Plugin
TouchSwipe is a jquery plugin to be used with jQuery on touch input devices such as iPad, iPhone etc.
Top Related Projects
A javascript library for multi-touch gestures :// You can touch this
The world's most versatile desktop notifications framework :earth_americas:
Most modern mobile touch slider with hardware accelerated transitions
Smooth scrolling for the web
:ok_hand: Drag and drop so simple it hurts
🚀 Performance focused, lightweight scroll animation library 🚀
Quick Overview
TouchSwipe-Jquery-Plugin is a jQuery plugin that enables touch swipe gestures on mobile and desktop devices. It provides a simple way to add swipe functionality to web elements, supporting various swipe directions and customizable options.
Pros
- Easy to implement and integrate with existing jQuery projects
- Supports both touch and mouse events, making it versatile for different devices
- Highly customizable with numerous options and callbacks
- Lightweight and performant
Cons
- Depends on jQuery, which may not be ideal for modern web development practices
- Last updated in 2018, potentially lacking support for newer browsers or devices
- Documentation could be more comprehensive and up-to-date
- May have compatibility issues with some mobile browsers or devices
Code Examples
- Basic swipe detection:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
console.log("You swiped " + direction);
}
});
- Configuring swipe threshold and direction:
$("#element").swipe({
threshold: 50,
allowPageScroll: "vertical",
swipeLeft: function() {
console.log("Swiped left");
},
swipeRight: function() {
console.log("Swiped right");
}
});
- Using pinch and zoom gestures:
$("#element").swipe({
pinchIn: function(event, direction, distance, duration, fingerCount, pinchZoom) {
console.log("Pinched in by " + pinchZoom);
},
pinchOut: function(event, direction, distance, duration, fingerCount, pinchZoom) {
console.log("Pinched out by " + pinchZoom);
}
});
Getting Started
- Include jQuery and the TouchSwipe plugin in your HTML:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="path/to/jquery.touchSwipe.min.js"></script>
- Initialize TouchSwipe on your desired element:
$(document).ready(function() {
$("#element").swipe({
swipe: function(event, direction) {
alert("You swiped " + direction);
}
});
});
- Customize the swipe options as needed:
$("#element").swipe({
threshold: 75,
allowPageScroll: "vertical",
swipeLeft: function() {
console.log("Swiped left");
},
swipeRight: function() {
console.log("Swiped right");
}
});
Competitor Comparisons
A javascript library for multi-touch gestures :// You can touch this
Pros of Hammer.js
- Framework-agnostic, works with vanilla JavaScript
- Supports a wider range of gestures (e.g., pinch, rotate)
- More actively maintained with regular updates
Cons of Hammer.js
- Larger file size, potentially impacting page load times
- Steeper learning curve for basic implementations
- May require more setup for simple swipe gestures
Code Comparison
TouchSwipe-Jquery-Plugin:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
console.log("You swiped " + direction);
}
});
Hammer.js:
var hammer = new Hammer(document.getElementById("element"));
hammer.on("swipe", function(ev) {
console.log("You swiped " + ev.direction);
});
Both libraries offer simple ways to implement swipe gestures, but Hammer.js provides a more versatile approach for handling various touch events. TouchSwipe-Jquery-Plugin is more straightforward for basic swipe detection in jQuery-based projects, while Hammer.js offers greater flexibility and support for complex gestures across different frameworks.
The world's most versatile desktop notifications framework :earth_americas:
Pros of push.js
- Focused on browser push notifications, providing a more specialized functionality
- Lightweight and doesn't require jQuery as a dependency
- Supports multiple browsers and devices
Cons of push.js
- Limited to push notifications, less versatile for general touch interactions
- May require additional setup for service workers in some cases
- Smaller community and fewer contributors compared to TouchSwipe-Jquery-Plugin
Code Comparison
push.js:
Push.create("Hello world!", {
body: "How's it hangin'?",
icon: '/icon.png',
timeout: 4000,
onClick: function () {
window.focus();
this.close();
}
});
TouchSwipe-Jquery-Plugin:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
console.log("You swiped " + direction);
}
});
The code snippets demonstrate the different focus of each library. push.js is designed for creating browser notifications, while TouchSwipe-Jquery-Plugin handles touch gestures and swipe events.
Most modern mobile touch slider with hardware accelerated transitions
Pros of Swiper
- More feature-rich with advanced functionality like parallax effects, lazy loading, and virtual slides
- Modern architecture with better performance and smaller file size
- Supports both JavaScript and framework-specific versions (React, Vue, Angular)
Cons of Swiper
- Steeper learning curve due to more complex API
- Requires more setup and configuration for basic use cases
- Larger bundle size when using all features
Code Comparison
TouchSwipe-Jquery-Plugin:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
console.log("You swiped " + direction);
}
});
Swiper:
const swiper = new Swiper('.swiper-container', {
direction: 'horizontal',
loop: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
TouchSwipe-Jquery-Plugin is simpler to implement for basic swipe detection, while Swiper requires more configuration but offers more advanced features out of the box. Swiper's code is more modular and customizable, allowing for complex slide-based interactions.
Smooth scrolling for the web
Pros of iScroll
- Supports more advanced scrolling features like zoom, infinite scrolling, and snap-to-element
- Lightweight and doesn't require jQuery as a dependency
- Better performance for complex scrolling scenarios
Cons of iScroll
- Steeper learning curve due to more complex API
- Less frequently updated compared to TouchSwipe
- May have compatibility issues with older browsers
Code Comparison
TouchSwipe:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
console.log("You swiped " + direction);
}
});
iScroll:
var myScroll = new IScroll('#wrapper', {
scrollX: true,
scrollY: true,
mouseWheel: true,
wheelAction: 'zoom'
});
TouchSwipe focuses on simple touch gestures, while iScroll provides more comprehensive scrolling functionality. TouchSwipe's API is more straightforward, making it easier to implement basic swipe detection. iScroll, on the other hand, offers a wider range of scrolling options and behaviors, but requires more configuration.
Both libraries serve different purposes: TouchSwipe is ideal for simple touch interactions, while iScroll is better suited for creating custom scrolling experiences, especially in mobile web applications or when dealing with complex scrolling requirements.
:ok_hand: Drag and drop so simple it hurts
Pros of Dragula
- Framework-agnostic, works with any JavaScript project
- Simpler API and easier to set up
- Supports nested draggable elements
Cons of Dragula
- Limited to drag-and-drop functionality
- Fewer customization options for touch events
- Smaller community and less frequent updates
Code Comparison
TouchSwipe-Jquery-Plugin:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
// Handle swipe
}
});
Dragula:
dragula([document.querySelector('#left'), document.querySelector('#right')])
.on('drag', function(el) {
// Handle drag
});
TouchSwipe-Jquery-Plugin offers more comprehensive touch event handling, including swipe gestures and multi-touch support. It's jQuery-dependent but provides extensive customization options for mobile interactions.
Dragula focuses solely on drag-and-drop functionality, offering a simpler API that works across frameworks. It's more lightweight and easier to implement for basic drag-and-drop needs, but lacks the broader touch event capabilities of TouchSwipe-Jquery-Plugin.
Choose TouchSwipe-Jquery-Plugin for complex touch interactions in jQuery projects, or Dragula for straightforward drag-and-drop functionality in any JavaScript environment.
🚀 Performance focused, lightweight scroll animation library 🚀
Pros of sal
- Lightweight and dependency-free, making it easier to integrate into projects
- Supports a wider range of animation effects beyond touch interactions
- More modern approach to animations, focusing on scroll-based triggers
Cons of sal
- Limited to scroll-based animations, less versatile for touch interactions
- May require more manual configuration for complex animations
- Smaller community and fewer resources compared to the more established TouchSwipe-Jquery-Plugin
Code Comparison
sal:
sal({
threshold: 0.5,
once: false,
animateClassName: 'animate__animated',
});
TouchSwipe-Jquery-Plugin:
$("#element").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
// Handle swipe
}
});
The code snippets demonstrate the different focus of each library. sal is configured for scroll-based animations, while TouchSwipe-Jquery-Plugin is set up to handle touch interactions. sal's configuration is more straightforward, but TouchSwipe offers more granular control over touch events.
TouchSwipe-Jquery-Plugin is better suited for projects requiring specific touch gesture handling, while sal is ideal for creating scroll-triggered animations with minimal setup. The choice between the two depends on the project's specific requirements and the desired user interaction model.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
TouchSwipe 1.6
A jQuery plugin to be used on touch devices such as iPad, iPhone, Android etc.
Detects single and multiple finger swipes, pinches and falls back to mouse 'drags' on the desktop.
Time and distance thresholds can be set to distinguish between swipe gesture and slow drag.
Allows exclusion of child elements (interactive elements) as well allowing page scrolling or page zooming depending on configuration.
- Detects swipes in 4 directions, "up", "down", "left" and "right"
- Detects pinches "in" and "out"
- Supports single finger or double finger touch events
- Supports click events both on the touchSwipe object and its child objects
- Definable threshold / maxTimeThreshold to determin when a gesture is actually a swipe
- Events triggered for swipe "start","move","end" and "cancel"
- End event can be triggered either on touch release, or as soon as threshold is met
- Allows swiping and page scrolling
- Disables user input elements (Button, form, text etc) from triggering swipes
Demos, examples and docs
http://labs.rampinteractive.co.uk/touchSwipe
http://labs.rampinteractive.co.uk/touchSwipe/docs
Installation
NPM
npm install jquery-touchswipe --save
Bower
bower install jquery-touchswipe --save
Manual
Include the minified file in your project.
<script type="text/javascript" src="js/jquery.touchSwipe.min.js"></script>
Usage
$(function() {
$("#test").swipe( {
//Generic swipe handler for all directions
swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
$(this).text("You swiped " + direction );
}
});
//Set some options later
$("#test").swipe( {fingers:2} );
});
For full demos, code examples and documentation, see below.
Development
Install dependencies
npm install
To minify
npm run minify
To build docs
npm run docs
To do both
npm run build
For port to XUI see:
Top Related Projects
A javascript library for multi-touch gestures :// You can touch this
The world's most versatile desktop notifications framework :earth_americas:
Most modern mobile touch slider with hardware accelerated transitions
Smooth scrolling for the web
:ok_hand: Drag and drop so simple it hurts
🚀 Performance focused, lightweight scroll animation library 🚀
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot