
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
webgl-carousel
Advanced tools
A high-performance image carousel library powered by WebGL with stunning visual effects
日本語 | English
A high-performance image carousel library powered by WebGL with stunning visual effects.
Check out our interactive demo to see all effects in action and experiment with custom shaders.
npm install webgl-carousel
Or using yarn:
yarn add webgl-carousel
Or using pnpm:
pnpm add webgl-carousel
import { WebGLCarousel } from 'webgl-carousel';
<script src="https://unpkg.com/webgl-carousel/dist/webgl-carousel.umd.js"></script>
<script>
const carousel = new WebGLCarousel.WebGLCarousel({
container: '#carousel',
images: [...]
});
</script>
const { WebGLCarousel } = require('webgl-carousel');
import { WebGLCarousel } from 'webgl-carousel';
const carousel = new WebGLCarousel({
container: '#carousel',
images: [
'path/to/image1.jpg',
'path/to/image2.jpg',
'path/to/image3.jpg'
],
effect: 'fade',
autoplay: true,
autoplayInterval: 3000
});
import { ReactCarousel } from 'webgl-carousel/react';
function App() {
const images = [
'path/to/image1.jpg',
'path/to/image2.jpg',
'path/to/image3.jpg'
];
return (
<ReactCarousel
images={images}
effect="slide"
autoplay
transitionDuration={1500}
style={{ width: '100%', height: '400px' }}
/>
);
}
<template>
<VueCarousel
:images="images"
effect="wave"
:autoplay="true"
:transition-duration="2000"
style="width: 100%; height: 400px;"
/>
</template>
<script setup>
import { VueCarousel } from 'webgl-carousel/vue';
const images = [
'path/to/image1.jpg',
'path/to/image2.jpg',
'path/to/image3.jpg'
];
</script>
<script>
import { SvelteCarousel } from 'webgl-carousel/svelte';
const images = [
'path/to/image1.jpg',
'path/to/image2.jpg',
'path/to/image3.jpg'
];
</script>
<SvelteCarousel
{images}
effect="flip"
autoplay={true}
transitionDuration={1800}
style="width: 100%; height: 400px;"
/>
fade
- Fade transitionslideLeft
/ slideRight
- Horizontal slideslideUp
/ slideDown
- Vertical slideflipHorizontal
/ flipVertical
- 3D flip rotationwave
/ gentleWave
/ intenseWave
- Wave distortiondistortion
/ subtleDistortion
/ extremeDistortion
- Lens distortiondissolve
/ smoothDissolve
- Dissolve transitionpixelDissolve
- Pixelated dissolvecircle
/ circleFromCenter
/ circleFromCorner
- Circular revealmorph
- Morphing transitionglitch
- Glitch effectOption | Type | Default | Description |
---|---|---|---|
container | string | HTMLElement | - | Container element or selector |
images | string[] | - | Array of image URLs |
effect | string | 'fade' | Transition effect name |
autoplay | boolean | false | Enable autoplay |
autoplayInterval | number | 3000 | Autoplay interval (ms) |
transitionDuration | number | 1000 | Transition duration (ms) |
navigation | boolean | true | Show navigation arrows |
pagination | boolean | true | Show pagination dots |
loop | boolean | true | Enable infinite loop |
preload | boolean | true | Preload all images |
next()
- Go to next imageprevious()
- Go to previous imagegoTo(index)
- Go to specific imagesetEffect(effectName)
- Change transition effectregisterEffect(effect)
- Register custom effectgetAvailableEffects()
- Get list of available effectsplay()
- Start autoplaypause()
- Stop autoplaysetAutoplay(enabled, interval?)
- Configure autoplaygetCurrentIndex()
- Get current image indexgetImageCount()
- Get total image countisReady()
- Check if carousel is readycarousel.on('ready', () => {
console.log('Carousel is ready');
});
carousel.on('imageChange', (index) => {
console.log('Current image:', index);
});
carousel.on('transitionStart', (from, to) => {
console.log('Transition started:', from, '->', to);
});
carousel.on('transitionEnd', (index) => {
console.log('Transition ended:', index);
});
Create your own transition effects using GLSL shaders:
import { createCustomEffect } from 'webgl-carousel';
const myEffect = createCustomEffect(
'myEffect',
null, // Use default vertex shader
`
precision mediump float;
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform float uProgress;
uniform vec2 uResolution;
uniform vec2 uImageSize0;
uniform vec2 uImageSize1;
varying vec2 vTexCoord;
vec2 getCoverUV(vec2 uv, vec2 imageSize, vec2 resolution) {
float imageAspect = imageSize.x / imageSize.y;
float screenAspect = resolution.x / resolution.y;
vec2 scale = vec2(1.0);
if (imageAspect > screenAspect) {
// Image is wider, scale by height
scale.x = imageAspect / screenAspect;
} else {
// Image is taller, scale by width
scale.y = screenAspect / imageAspect;
}
return (uv - 0.5) / scale + 0.5;
}
void main() {
vec2 uv0 = getCoverUV(vTexCoord, uImageSize0, uResolution);
vec2 uv1 = getCoverUV(vTexCoord, uImageSize1, uResolution);
// Your custom transition logic here
vec4 color0 = texture2D(uTexture0, uv0);
vec4 color1 = texture2D(uTexture1, uv1);
gl_FragColor = mix(color0, color1, uProgress);
}
`
);
carousel.registerEffect(myEffect);
carousel.setEffect('myEffect');
The library automatically falls back to Canvas 2D rendering when WebGL is not available.
You can use WebGL Carousel directly from a CDN:
<!-- Latest version -->
<script src="https://unpkg.com/webgl-carousel"></script>
<!-- Specific version -->
<script src="https://unpkg.com/webgl-carousel@0.2.3"></script>
WebGL Carousel is written in TypeScript and includes type definitions out of the box.
import { WebGLCarousel, WebGLCarouselOptions } from 'webgl-carousel';
const options: WebGLCarouselOptions = {
container: '#carousel',
images: ['image1.jpg', 'image2.jpg'],
effect: 'fade',
autoplay: true
};
const carousel = new WebGLCarousel(options);
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see the LICENSE file for details.
Check out the examples directory for more usage examples:
This library uses WebGL for hardware-accelerated rendering and provides fallback support for broader compatibility.
FAQs
A high-performance image carousel library powered by WebGL with stunning visual effects
We found that webgl-carousel demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.