This time I will share jQuery Plugin and tutorial about Touchable jQuery Lightbox Plugin – swipebox, hope it will help you in programming stack.
swipebox is a jQuery plugin that makes it possible to create a highly customizable and touchable lightbox for desktop, mobile, and tablet.
It supports swipe gestures, keyboard navigation, CSS transitions, retina and is compatible with Chrome, Safari, Firefox, Opera, IE8+, iOS+, Android, and Windows Phone.
How to use it:
1. Include the swipebox CSS in your page’s head section.
1 |
< link rel = "stylesheet" href = "/path/to/src/css/swipebox.min.css" /> |
2. Add a link to your thumbnail image and define the image caption in the title
attribute:
1 |
< a href = "/path/to/full.jpg" class = "swipebox" title = "Caption Here" > |
2 |
< img src = "/path/to/thumb.jpg" alt = "Image Alt" > |
3. Include jQuery library and the swipebox.js plugin on the page.
1 |
< script src = "/path/to/cdn/jquery.min.js" ></ script > |
2 |
< script src = "/path/to/src/js/jquery.swipebox.min.js" ></ script > |
4. To create a gallery lightbox, make sure all links have the same rel
value.
01 |
< a href = "/path/to/full-1.jpg" class = "swipebox" title = "Caption Here" rel = "gallery" > |
02 |
< img src = "/path/to/thumb-1.jpg" alt = "Image Alt" > |
05 |
< a href = "/path/to/full-2.jpg" class = "swipebox" title = "Caption Here" rel = "gallery" > |
06 |
< img src = "/path/to/thumb-2.jpg" alt = "Image Alt" > |
09 |
< a href = "/path/to/full-3.jpg" class = "swipebox" title = "Caption Here" rel = "gallery" > |
10 |
< img src = "/path/to/thumb-3.jpg" alt = "Image Alt" > |
5. Not only image, the plugin supports Youtube or Vimeo videos:
1 |
< a class = "swipebox" rel = "viemo" href = "/path/to/vimeoVideo" > |
5 |
< a class = "swipebox" href = "/path/to/youtubeVideo" > |
6. Call the plugin on the image or video links and done.
2 |
$( ".swipebox" ).swipebox(); |
7. You are also allowed to load images into the lightbox via JavaScript:
1 |
$( ".swipebox" ).swipebox([ |
2 |
{ href: 'image-1.jpg' , title: 'Caption 1' }, |
3 |
{ href: 'image-2.jpg' , title: 'Caption 2' }, |
8. Full plugin options to customize the lightbox.
01 |
$( ".swipebox" ).swipebox({ |
10 |
initialIndexOnArray: 0, |
13 |
removeBarsOnMobile : true , |
16 |
hideCloseButtonOnMobile : false , |
28 |
autoplayVideos: false , |
34 |
toggleClassOnLoad: '' , |
38 |
beforeOpen: function (){} , |
44 |
afterClose: function (){}, |
47 |
afterMedia: function (){}, |
Changelog:
2021-01-23
- jQuery.isArray is deprecated; use Array.isArray
2021-01-08
2021-01-06
2016-03-15
2014-09-15
2014-07-07
- support for any url with variable swipeboxVideo=1
2014-04-07
- Added hideBarsOnMobile option, clean up
2014-04-04
- Added options to disable SVG and fixed IE bug
2014-03-14
- Detect touchable device with user agent AND touch event check
2013-03-14
- Improved bar animation and gesture detection