This is an image gallery for Svelte based on react-image-gallery v1.2.11. Many thanks to all the contributors of that package for their hard work!
react2svelte.github.io/image-gallery/.
React image gallery is a React component for building image galleries and carousels
play, pause, slide, beforeslide, screenchange, imageload, imageerror, click eventsNot yet ported
Install the library
npm i @react2svelte/image-gallery
Use it in your component/page
<script lang="ts">
import ImageGallery from '@react2svelte/image-gallery';
const images = [
{
original: 'https://picsum.photos/id/1018/1000/600/',
thumbnail: 'https://picsum.photos/id/1018/250/150/'
},
{
original: 'https://picsum.photos/id/1015/1000/600/',
thumbnail: 'https://picsum.photos/id/1015/250/150/'
},
{
original: 'https://picsum.photos/id/1019/1000/600/',
thumbnail: 'https://picsum.photos/id/1019/250/150/'
}
];
</script>
<ImageGallery items="{images}" />
You can also have a look at the demo page of the package, it allows setting library settings interactively. To run it locally:
git clone https://github.com/react2svelte/image-gallery.git
cd image-gallery
npm install
npm run dev
And open http://localhost:5173/
items: (required) Array of objects, see example above,original - image src urlthumbnail - image thumbnail src urlfullscreen - image for fullscreen (defaults to original)originalHeight - image height (html5 attribute)originalWidth - image width (html5 attribute)loading - image loading. Either "lazy" or "eager" (html5 attribute)thumbnailHeight - image height (html5 attribute)thumbnailWidth - image width (html5 attribute)thumbnailLoading - image loading. Either "lazy" or "eager" (html5 attribute)originalClass - custom image classthumbnailClass - custom thumbnail classrenderItem - Function for custom rendering a specific slide (see renderItem below)renderThumbInner - Function for custom thumbnail renderer (see renderThumbInner below)originalAlt - image altthumbnailAlt - thumbnail image altoriginalTitle - image titlethumbnailTitle - thumbnail image titlethumbnailLabel - label for thumbnaildescription - description for imagesrcSet - image srcset (html5 attribute)sizes - image sizes (html5 attribute)bulletClass - extra class for the bullet of the iteminfinite: Boolean, default truelazyLoad: Boolean, default falseshowNav: Boolean, default trueshowThumbnails: Boolean, default truethumbnailPosition: String, default bottomtop, right, bottom, leftshowFullscreenButton: Boolean, default trueuseBrowserFullscreen: Boolean, default trueuseTranslate3D: Boolean, default truetranslate instead of translate3d css property to transition slidesshowPlayButton: Boolean, default trueisRTL: Boolean, default falseshowBullets: Boolean, default falseshowIndex: Boolean, default falseautoPlay: Boolean, default falsedisableThumbnailScroll: Boolean, default falsedisableKeyDown: Boolean, default falsedisableSwipe: Boolean, default falsedisableThumbnailSwipe: Boolean, default falseonErrorImageURL: String, default undefinedindexSeparator: String, default ' / ', ignored if showIndex is falseslideDuration: Number, default 450swipingTransitionDuration: Number, default 0slideInterval: Number, default 3000slideOnThumbnailOver: Boolean, default falseflickThreshold: Number (float), default 0.4swipeThreshold: Number, default 30stopPropagation: Boolean, default falsestartIndex: Number, default 0additionalClass: String,useWindowKeyDown: Boolean, default truetrue, listens to keydown events on window (window.addEventListener)false, listens to keydown events on image gallery element (imageGalleryElement.addEventListener)The following functions can be accessed:
play(): plays the slidespause(): pauses the slidesfullScreen(): activates full screenexitFullScreen(): deactivates full screenslideToIndex(index): slides to a specific indexgetCurrentIndex(): returns the current indexAlready supported
slide: Function, details: { currentIndex: number }beforeslide: Function, details: { nextIndex: number }screenchange: Function, details: { fullscreen: boolean }pause: Function, details: { currentIndex: number }play: Function, details: { currentIndex: number }imageload: Function, details: { index: number, event }imageerror: Function, details: { index: number, event }click: Function, details: eventNot yet supported
onThumbnailError: Function, callback(event)onThumbnailClick: Function, callback(event, index)onTouchMove: Function, callback(event) on gallery slideonTouchEnd: Function, callback(event) on gallery slideonTouchStart: Function, callback(event) on gallery slideonMouseOver: Function, callback(event) on gallery slideonMouseLeave: Function, callback(event) on gallery slidereact-image-gallery supports rendering custom controls, this feature has not been ported yet.
MIT