iprodev/iView
À propos
iView is easy to use jQuery image slider with animated captions, responsive layout and HTML Elements like (Video, iFrame) slider. Easily add unlimited number of slides and captions. Use it as image slider, image gallery, banner rotator, banner ads, or even presentation.
Design et médiasProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginaliView Slider
iView is an image and content slider with 34 transition effects, animated captions, video slides, a responsive layout and full right-to-left support. Use it as an image slider, gallery, banner rotator, ad rotator or presentation.
v3 has no dependencies. It is plain JavaScript (14 KB gzipped), with an optional adapter that keeps the v2 jQuery API working on jQuery 3 and 4.
- 34 slide transitions: strips, curtains, blocks, zigzags, slides and fades
- Animated captions with 9 effects and 30+ easing curves
- Video slides (YouTube, Vimeo, any iframe or
<video>) - Pie, ring or bar timer; play/pause on click
- Bullets, thumbnails and a thumbnail tooltip
- Responsive: scales to its container, captions included
- Right-to-left layouts (Persian, Arabic, Kurdish, Hebrew...)
- Touch swipe, keyboard arrows, screen reader labels, respects "reduce motion"
- Whole-slide links, text-only slides, image maps
- A JavaScript API, callbacks and DOM events
Demos
Open the pages in demo/ from a local web server, for example npx serve . and then http://localhost:3000/demo/.
| Page | Shows |
|---|---|
| Regular | Bullets with a thumbnail tooltip, video slide, per-slide transitions |
| Multiple | Two sliders on one page, translated labels, ring timers |
| API | Thumbnail bar, bar timer, buttons that call the API, event log |
| Responsive | A fluid slider with bullets |
| Banner | 728×90 and 300×600 ad rotators with links |
| New in v3 | Links, text-only slides, percentage positions, loop: false, no timer |
| RTL | A Persian right-to-left page |
| jQuery | Unchanged v2 code running on jQuery 4 |
Install
npm install @iprodev/iview
Or download dist/ and include the files directly:
<link rel="stylesheet" href="dist/iview.css">
<script src="dist/iview.min.js"></script>
| File | Use |
|---|---|
iview.min.js / iview.js |
<script> tag, defines window.IView |
jquery.iview.min.js / jquery.iview.js |
Same, plus $.fn.iView (load jQuery first) |
iview.esm.js |
ES module: import IView from '@iprodev/iview' |
iview.cjs |
CommonJS: const { IView } = require('@iprodev/iview') |
jquery.iview.esm.js |
import { installJQuery } from '@iprodev/iview/jquery' |
iview.css / iview.min.css |
Base styles (layout only; a skin adds the look) |
iview.d.ts |
TypeScript types |
Quick start
<div id="slider">
<div data-iview-image="photos/1.jpg">
<div class="iview-caption" data-x="80" data-y="200" data-transition="wipeRight">Hello</div>
</div>
<div data-iview-image="photos/2.jpg" data-iview-thumbnail="photos/2_thumb.jpg"></div>
<div data-iview-image="photos/3.jpg" data-iview-transition="zigzag-top,fade"></div>
</div>
<script src="dist/iview.min.js"></script>
<script>
const slider = new IView('#slider', {
width: 900, // design size: caption positions use these coordinates
height: 500,
fx: 'random',
controlNav: true
});
</script>
Every child element of the slider is a slide. Set width and height to the size your images and caption positions were designed for. The slider then scales to fit its container. Without them, iView uses the element's CSS size, or else the first image's size.
With jQuery
v2 code keeps working. Load jQuery (1.9 or later; tested with 3.x and 4.x), then the jQuery build:
<script src="jquery.min.js"></script>
<script src="dist/jquery.iview.min.js"></script>
<script>
$('#slider').iView({ pauseTime: 7000, controlNav: true });
$('#slider').trigger('iView:pause'); // v2 commands still work
$('#slider').trigger('iView:goSlide', [2]);
$('#slider').iView('next'); // or call any method by name
const slider = $('#slider').iView('instance'); // the IView instance
</script>
As an ES module
import IView from '@iprodev/iview';
import '@iprodev/iview/css';
const slider = new IView(document.querySelector('.hero'), { fx: 'fade' });
Slides
Settings on a slide element. Each one works as data-iview-name and in the v2 form data-iview:name.
| Attribute | Value |
|---|---|
data-iview-image |
Image URL. Leave it out for a text-only slide, which fades in. |
data-iview-thumbnail |
Thumbnail URL for controlNavThumbs and the tooltip. Defaults to the image. |
data-iview-transition |
A transition for this slide, or a comma separated set to pick from at random. |
data-iview-easing |
Easing for this slide's transition. |
data-iview-pausetime |
How long this slide stays, in ms. |
data-iview-alt |
Alternative text for the image (also the link's accessible name). |
data-iview-link |
Makes the whole slide a link. |
data-iview-target |
Link target, e.g. _blank. |
data-iview-usemap |
usemap for the slide image, to use an image map. |
data-iview-type="video" |
A video slide, see below. |
data-iview-autoplay |
Video slides: open and play the video as soon as the slide is shown. |
Captions
Any element with the class iview-caption inside a slide is a caption. Captions are positioned in the design size (width × height), so they scale with the slider.
<div class="iview-caption" data-x="50" data-y="80%" data-width="300" data-transition="expandLeft"
data-speed="700" data-easing="easeOutBack">Caption text, <b>HTML</b> allowed</div>
| Attribute | Value |
|---|---|
data-x, data-y |
Position in px, a percentage ("10%"), or center (the default). In RTL, data-x is measured from the right edge. |
data-width, data-height |
Size in px. Defaults to the caption's natural size. |
data-transition |
fade (default), wipeLeft, wipeRight, wipeUp, wipeDown, expandLeft, expandRight, expandUp, expandDown. The v2 doc names wipeTop, wipeBottom, expandTop and expandBottom also work. |
data-speed |
Duration in ms. Default: captionSpeed. |
data-easing |
Easing name. Default: captionEasing. |
Captions play every time their slide is shown, one after another.
Video slides
Put the player as the first element of a slide with data-iview-type="video". Clicking the slide drops the player down over the slider and pauses the slideshow. Closing it, or moving to another slide, stops playback.
<div data-iview-image="photos/video-poster.jpg" data-iview-type="video">
<iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Video" allow="autoplay; fullscreen"></iframe>
<div class="iview-caption" data-x="450" data-y="340">Watch the video</div>
</div>
The iframe is loaded only when the video is opened. With videoAutoplay: true (the default) iView adds autoplay=1 to the URL so it starts at once. <video> elements are played and paused directly. Browsers block autoplay with sound when there was no click, so for data-iview-autoplay slides use a muted player (e.g. ?mute=1 on YouTube, muted on <video>).
Options
| Option | Default | Description |
|---|---|---|
fx |
'random' |
Transition: 'random', a name, or a set like 'left-curtain,fade,zigzag-top'. |
easing |
'easeOutQuad' |
Transition easing. |
strips |
20 |
Number of strips for strip effects. |
blockCols / blockRows |
10 / 5 |
Grid for block and zigzag effects. |
animationSpeed |
500 |
Transition speed in ms. |
pauseTime |
5000 |
How long each slide stays, in ms. |
startSlide |
0 |
First slide (zero-based). |
randomStart |
false |
Start on a random slide. |
autoAdvance |
true |
Play automatically. false starts paused. |
pauseOnHover |
false |
Pause while the mouse is over the slider. |
pauseOnHidden |
true |
Pause while the browser tab is hidden. |
loop |
true |
false stops on the last slide and disables previous/next at the ends. |
directionNav |
true |
Previous / next buttons. |
directionNavHoverOpacity |
0.6 |
Their opacity when the slider is not hovered. |
controlNav |
false |
Bullets (1, 2, 3...). |
controlNavNextPrev |
true |
Previous / next buttons in the control nav (only when directionNav is off). |
controlNavHoverOpacity |
0.6 |
Control nav opacity when not hovered. |
controlNavThumbs |
false |
Thumbnails instead of bullets. |
controlNavTooltip |
true |
Thumbnail preview when hovering a bullet. |
tooltipX / tooltipY |
5 / -5 |
Tooltip offset. |
captionSpeed |
500 |
Caption animation speed in ms. |
captionEasing |
'easeInOutSine' |
Caption easing. |
captionOpacity |
1 |
Caption opacity. |
keyboardNav |
true |
Left / right arrow keys. |
touchNav |
true |
Swipe with a finger, pen or mouse. |
nextLabel, previousLabel, playLabel, pauseLabel, closeLabel |
English | Button labels. Translate them for other languages. |
slideLabel |
'Slide {n} of {total}' |
Accessible name of each slide and bullet. |
ariaLabel |
'Image slider' |
Accessible name of the slider (unless it has aria-label). |
timer |
'Pie' |
'Pie', '360Bar', 'Bar', or 'none' / false. |
timerBg, timerColor |
'#000', '#EEE' |
Timer colors. |
timerOpacity |
0.5 |
Timer opacity. |
timerDiameter |
30 |
Diameter in px. For the bar timer, its width, which can be a percentage like '50%'. |
timerPadding, timerStroke |
4, 3 |
Padding and stroke width. |
timerBarStroke, timerBarStrokeColor, timerBarStrokeStyle |
1, '#EEE', 'solid' |
Border of the bar timer. |
timerPosition |
'top-right' |
top, middle or bottom plus left, center or right. Mirrored in RTL. |
timerX, timerY |
10, 10 |
Timer offset from that corner. |
width, height |
null |
Design size in px (see Quick start). |
responsive |
true |
Scale the slider to its container width. |
imageFit |
'cover' |
'cover', 'contain', 'fill' or 'none' (natural size, top left). |
rtl |
'auto' |
'auto' follows the CSS direction. true or false forces it. |
reducedMotion |
'auto' |
'auto' follows the OS "reduce motion" setting: quick fades instead of effects. |
preload |
'first' |
'first' starts once the first image loads and loads the rest in the background. 'all' waits for every image. |
videoAutoplay |
true |
Start playback when a video is opened. |
onBeforeChange, onAfterChange, onAfterLoad, onLastSlide, onSlideShowEnd, onPause, onPlay |
null |
Callbacks, see Events. onSlideshowEnd (the v2 docs spelling) works too. |
Change the defaults for every slider with IView.defaults.pauseTime = 8000.
Transitions
left-curtain, right-curtain, top-curtain, bottom-curtain, strip-down-right, strip-down-left, strip-up-right, strip-up-left, strip-up-down, strip-up-down-left, strip-left-right, strip-left-right-down, slide-in-right, slide-in-left, slide-in-up, slide-in-down, fade, block-random, block-fade, block-fade-reverse, block-expand, block-expand-reverse, block-expand-random, block-drop-random, zigzag-top, zigzag-bottom, zigzag-grow-top, zigzag-grow-bottom, zigzag-drop-top, zigzag-drop-bottom, strip-left-fade, strip-right-fade, strip-top-fade, strip-bottom-fade.
Unknown names fall back to fade. The list is available as IView.transitions.
Easing
linear, swing, and easeIn, easeOut and easeInOut versions of Quad, Cubic, Quart, Quint, Sine, Expo, Circ, Elastic, Back and Bounce (e.g. easeOutBounce). These are the jQuery Easing names, so no easing plugin is needed. CSS values work too: ease-in-out, cubic-bezier(.17,.67,.83,.67), or any function t => t.
Add your own: IView.easing.myCurve = (t) => t * t;
API
const slider = new IView('#slider', options);
slider.next(); // returns a Promise<boolean>; false if a transition is running
slider.prev();
slider.goTo(2); // zero-based
slider.pause();
slider.play();
slider.toggle();
slider.refresh(); // re-measure after the container changed size while hidden
slider.destroy(); // restore the original markup
slider.index; // current slide
slider.total;
slider.paused;
slider.isAnimating;
slider.slides; // the slide elements
IView.getInstance('#slider');
IView.init('.slider', options); // one slider per matching element
Events
Each event is available three ways: as an option callback, through slider.on(), and as a DOM event on the slider element. Every handler gets the same detail: { index, previous, total, slide, instance }.
| Callback | on() name |
DOM event | When |
|---|---|---|---|
onAfterLoad |
load |
iview:load |
The first slide is ready |
onBeforeChange |
beforeChange |
iview:beforechange |
A transition starts (index is the incoming slide) |
onAfterChange |
afterChange |
iview:afterchange |
A transition ended |
onLastSlide |
lastSlide |
iview:lastslide |
The last slide is shown |
onSlideShowEnd |
end |
iview:end |
Every slide has been shown (it wraps to the first, or stops with loop: false) |
onPause / onPlay |
pause / play |
iview:pause / iview:play |
Paused or resumed |
videoOpen / videoClose |
iview:videoopen / iview:videoclose |
A video slide was opened or closed | |
destroy |
iview:destroy |
destroy() was called |
slider.on('afterChange', ({ index }) => console.log('Now on slide', index + 1));
document.querySelector('#slider').addEventListener('iview:end', () => console.log('Done'));
Right-to-left
When the slider is in a right-to-left context (dir="rtl" or direction: rtl), iView mirrors the whole layout:
- "Previous" sits on the right and "next" on the left; bullets start from the right
- The Left arrow key and a swipe to the right go to the next slide
data-xon captions andtimerPosition/timerXare measured from the right edge- Horizontal effects run the other way (
slide-in-rightbecomesslide-in-left, and so on)
Skins written for left-to-right work unchanged: in RTL the "previous" button gets the iview-nextNav class (right side, right arrow). Use data-action="prev" / data-action="next" if you need to tell them apart. Set rtl: true or rtl: false to force a direction.
Responsive layout
The slider is laid out at its design size (width × height) and scaled to the container's width with a CSS transform, so captions keep their positions and proportions. The container's height follows. Give the slider a fluid width, e.g. max-width: 900px, and it works on any screen. Set responsive: false to keep the fixed size.
Accessibility
The slider is a labelled region with aria-roledescription="carousel". Slides are labelled groups and the buttons are keyboard-focusable with Enter and Space. Slide changes are announced politely while the slider is paused. The OS "reduce motion" setting turns effects into short fades.
Styling
dist/iview.css holds the functional layout only. A skin adds the look: see the five in demo/assets/skins. Class names:
| Element | Class |
|---|---|
| Slider | .iview (+ .iview-ready, .iview-loading, .iview-hover, .iview-paused, .iview-rtl) |
| Stage | .iviewSlider |
| Slide | .iview-slide, .iview-active; image .iview-slide-image; link .iview-link |
| Transition pieces | .iview-strip, .iview-block |
| Previous / next | .iview-directionNav > a.iview-prevNav, a.iview-nextNav |
| Bullets | .iview-controlNav > .iview-items > ul > li > a.iview-control(.active), plus a.iview-controlPrevNav, a.iview-controlNextNav |
| Tooltip | .iview-tooltip > .holder > .container > div > img |
| Captions | .iview-caption > .caption-contain |
| Timer | .iview-timer (.paused), .iview-timer-pie, .iview-timer-360bar, .iview-timer-bar |
| Preloader | .iview-preloader > div |
| Video | .iview-video (slide), .iview-video-show > .iview-video-container > a.iview-video-close |
Disabled button (loop: false) |
.iview-disabled |
Upgrading from v2
Most v2 pages only need the new files. jQuery, Raphael.js and jQuery Easing are no longer needed:
<!-- v2 -->
<script src="jquery.js"></script>
<script src="raphael-min.js"></script>
<script src="jquery.easing.js"></script>
<script src="iview.js"></script>
<!-- v3, keeping the jQuery code -->
<script src="jquery.js"></script>
<script src="dist/jquery.iview.min.js"></script>
<!-- v3, without jQuery -->
<script src="dist/iview.min.js"></script>
Changes to check in custom skins and code:
- IDs became classes, so several sliders on one page no longer share IDs:
#iview-timer→.iview-timer,#iview-preloader→.iview-preloader,#iview-tooltip→.iview-tooltip. - The bar inside the bar timer is
.iview-timer-bar. - The active slide's image is now an
<img class="iview-slide-image">inside the slide, not the background of.iviewSlider. - Responsive scaling now keeps the slider's natural height: an element after the stage (like a thumbnail bar) is no longer covered.
onLastSlidefires when the last slide is shown (v2 fired it when leaving the last slide).- Callbacks receive a detail object (
{ index, previous, total, slide, instance }) andthisis the slider. - The old
data-iview:*attributes still work;data-iview-*is the valid HTML form. - Browser support is now modern browsers: Chrome and Edge 79+, Firefox 67+, Safari and iOS 13+. Internet Explorer is not supported. The v2 source remains available at commit
455079d.
See CHANGELOG.md for everything that changed.
Development
npm install
npm test # unit tests (Vitest + jsdom), including jQuery 3 and 4
npm run build # writes dist/
npm run dev # rebuild on change
| Path | Contents |
|---|---|
src/iview.js |
The IView class |
src/transitions.js |
The 34 slide transitions |
src/timer.js |
SVG pie / ring and bar timers |
src/tween.js, src/easing.js |
Animation engine and easing curves |
src/jquery.js |
jQuery adapter |
src/iview.css, src/iview.d.ts |
Base styles and TypeScript types |
demo/ |
Demo pages, skins and photos |
test/ |
Tests |
dist/ is committed so the files can be used straight from GitHub. Run npm run build before committing source changes.
License
Explorer des projets similaires
Chargement…