Strip
An Unobtrusive Responsive Lightbox
Strip is a Lightbox that only partially covers the page. This leaves room to interact with the page on larger screens while giving smaller devices the classic Lightbox experience.
Usage
Installation
Include Strip below the latest 3.x release of jQuery:
<script
type="text/javascript"
src="https://code.jquery.com/jquery-3.6.0.min.js"
></script>
<script type="text/javascript" src="/js/strip.pkgd.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/strip.css" />
Alternatively Strip can be installed using npm:
npm install @staaky/strip
Basic Usage
The most basic way to use Strip is by adding the class strip
to a link:
<a href="image.jpg" class="strip">Show image</a>
A caption can be added using the data-strip-caption attribute:
<a href="image.jpg" class="strip" data-strip-caption="Caption below the image"
>Caption</a
>
Or customize Strip by putting options on the data-strip-options
attribute:
<a
href="http://vimeo.com/32071937"
class="strip"
data-strip-options="side: 'top'"
>Options</a
>
Groups
Create groups by giving links a data-strip-group
attribute with a unique name:
<a href="image1.jpg" class="strip" data-strip-group="mygroup">Image 1</a>
<a href="image2.jpg" class="strip" data-strip-group="mygroup">Image 2</a>
The data-strip-group-options
attribute can be used to set options for all items in the group:
<a
href="image1.jpg"
class="strip"
data-strip-group="shared-options"
data-strip-group-options="loop: false, maxWidth: 500"
>This group</a
>
<a href="image2.jpg" class="strip" data-strip-group="shared-options"
>has shared options</a
>
Media types
Strip attempts to automatically detect the media type using the given url. The type can also be set to one of the following values using the data-strip-type
attribute: image
, youtube
or vimeo
.
Image
Most of the time setting the type will not be required for images, it will be required in cases where Strip cannot detect it based on the url:
<a href="/images/?id=69420" class="strip" data-strip-type="image">Image</a>
Youtube
Strip will detect Youtube links and automatically embed them:
<a href="http://www.youtube.com/watch?v=c0KYU2j0TM4" class="strip">Youtube</a>
Options can be set using the youtube
option, see YouTube Embedded Players and Player Parameters for all the available options.
<a
href="http://www.youtube.com/watch?v=5XD2kNopsUs"
class="strip"
data-strip-options="
width: 853,
height: 480,
youtube: { autoplay: 0 }
"
>Youtube - Dimensions and options</a
>
Vimeo
Strips embeds Vimeo videos using the Vimeo Player API.
<a href="http://vimeo.com/32071937" class="strip">Vimeo</a>
Options can be set using the vimeo
option, see Vimeo Player Embedding for all the available options.
Javascript API
The API allows Strip to be used with Javascript, as an alternative to using the strip
class on links.
Method | |
---|---|
|
A single item can be shown by giving Strip.show("image.jpg"); Add a caption by using an object instead: Strip.show({
url: "image.jpg",
caption: "Caption for this image",
}); This object also accepts options to customize Strip: Strip.show({
url: "http://vimeo.com/32071937",
options: {
side: "top",
},
}); GroupsGroups can be shown by giving // use urls
Strip.show(["image1.jpg", "image2.jpg"]);
// or objects
Strip.show([
{ url: "image1.jpg", caption: "Caption for this image" },
{ url: "image2.jpg", caption: "Another caption" },
]); Options for the entire group can be set using the second argument: Strip.show(["image1.jpg", "image2.jpg"], {
loop: false,
maxWidth: 500,
}); Open Strip at a specific position by setting a number as the last argument: Strip.show(["image1.jpg", "image2.jpg"], 2); LinksLinks that use the strip class can also be opened by passing Strip.show($("#elementid")[0]); |
|
Close Strip at any time by calling Strip.hide(); |
|
Disables Strip. When disabled, links using the Strip.disable(); Use Strip.fallback(false).disable(); |
|
Enable Strip if it was previously disabled. Strip.enable(); |
|
When Strip is disabled it will fallback to making Strip.fallback(false); |
|
Sets the name of the default skin, this skin will be used when no Strip.setDefaultSkin("custom"); |
Options
Option | |
---|---|
|
Sets the duration of individual effects, or disables them when set to false.
These are all available effects: effects: {
spinner: { show: 200, hide: 200 },
transition: { min: 175, max: 250 },
ui: { show: 0, hide: 200 },
window: { show: 300, hide: 300 }
} |
|
Hide Strip when clicking outside of it or an element that could open it, enabled by default.
|
|
Enable or disable individual keyboard buttons or all of them when set to false.
Or use an object to toggle individual buttons: keyboard: {
left: true,
right: true,
esc: false
} Note: |
|
When set to true a group becomes a loop, making it possible to move between the first and last item:
|
|
Sets a maximum height for the content.
|
|
Sets a maximum width for the content.
|
|
Allows buttons to overlap the content when set to true, which is the default. Disabling overlap will cause buttons to be positioned outside of the content.
Note: Vimeo and Youtube always have |
|
Show or hide the position indicator.
|
|
Sets the items to preload before and after the current item, or disables preloading when set to false.
|
|
Set the side to position Strip on to
|
|
Sets the skin. If you've provided default options for this skin they'll be applied as a starting point for other options. The default skin is
|
|
Disables the loading icon when set to false.
|
|
Clicking elements will toggle Strip, this behavior can be disabed by setting
Note: |
|
Sets the player parameters of a Vimeo video, available options can be found in the Vimeo documentation: Vimeo Player Embedding. vimeo: {
autoplay: 1,
title: 1,
byline: 1,
portrait: 0,
loop: 0
} |
|
youtubeSets the player parameters of a Youtube video, available options can be found in the Youtube documentation: YouTube Embedded Players and Player Parameters. youtube: {
autohide: 1,
autoplay: 1,
controls: 1,
enablejsapi: 1,
hd: 1,
iv_load_policy: 3,
loop: 0,
modestbranding: 1,
rel: 0
} |
Callbacks
Callbacks can be used alongside other Options.
Callback | |
---|---|
|
A function to call after the position changed. The first argument is the current position within the group. afterPosition: function(position) {
console.log("You've reached position " + position);
} |
|
A function to call after Strip is fully hidden. afterHide: function() {
console.log('Strip is no longer visible');
} |
|
This callback allows you to respond to Strip as it's resizing and make adjustments to your page. You could for example slide your page along or adjust margins. The parameters of onResize give you everything needed to make these adjustments. onResize: function(fxProperty, fxValue, side) {
console.log(fxProperty, fxValue, side);
// logs: 'width', 0, 'right' when starting the animation
// and adjusts fxValue for each step in the animation
}
|
|
A function to call when Strip comes into view. onShow: function() {
console.log('Strip is visible');
} |
Skins
Custom skins can be added by copying the existing default skin called strip
, rename it and modify it to your needs. It's recommended to do this in a separate css file so that strip.css
can be upgraded without losing anything.
Once you have a skin in place it can be used with the skin
option:
skin: 'custom'
Default options
Default options can be provided for a skin by extending Strip.Skins
with options for your custom skin:
$.extend(Strip.Skins, {
custom: {
loop: false,
},
});
Changing the default skin
The default skin can be changed using Strip.setDefaultSkin()
.
Strip.setDefaultSkin("custom");