Drag/Swipe To Scroll Plugin With jQuery - dragScroll.js
File Size: | 6.52 KB |
---|---|
Views Total: | 8581 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

Yet another jQuery based drag to scroll plugin which allows users to move content in a scrollable area horizontally or vertically using mouse drag (desktop) or touch swipe events (mobile).
How to use it:
1. Add your long content to a scrollable container. In this example, we're going to apply a panning functionality to an image.
<div class="drag-box"> <!-- draggable content --> <div class="drag"> <img src="https://source.unsplash.com/KZc9h88nwpM/1600x900"> </div> </div>
.drag-box{ width: 400px; height: 300px; overflow: hidden; }
2. Load the JavaScript file jquery.dragscroll.min.js
after loading jQuery library.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script> <script src="js/jquery.dragscroll.min.js"></script>
3. Attach the plugin to the draggable content and done.
$(function(){ $('.drag').dragscroll(); });
4. Limit the direction of scrolling: horizontal or vertical. Default: both.
$('.drag').dragScroll({ direction: 'scrollLeft' }); $('.drag').dragscroll({ direction: 'scrollTop' });
5. Trigger functions on start/end/move.
$('.drag').dragScroll({ onStart: function($this) { console.log($this); }, onMove: function($this) { console.log($this); }, onEnd: function($this) { console.log($this); } });
Changelog:
2021-05-30
- Renamed method name
dragscroll
todragScroll
.
2020-05-10
- JS Update
This awesome jQuery plugin is developed by YuTingtao. For more Advanced Usages, please check the demo page or visit the official website.