GPU加速による滑らかなアニメーションと美しいトランジションエフェクト
WebGLによるGPU加速で60fpsの滑らかなアニメーションを実現
15種類以上のビルトインエフェクトとカスタムシェーダーサポート
モバイルデバイスでも快適に動作するタッチジェスチャー対応
React、Vue、Svelteなど主要フレームワークをサポート
独自のGLSLシェーダーを使用してオリジナルエフェクトを作成
WebGL非対応環境でもCanvas 2Dによる代替表示
npm install webgl-carousel
yarn add webgl-carousel
<script src="https://unpkg.com/webgl-carousel/dist/webgl-carousel.umd.js"></script>
import { WebGLCarousel } from 'webgl-carousel';
const carousel = new WebGLCarousel.WebGLCarousel({
container: '#carousel',
images: [
'path/to/image1.jpg',
'path/to/image2.jpg',
'path/to/image3.jpg'
],
effect: 'fade',
autoplay: true,
transitionDuration: 2000
});
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="slideLeft"
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;"
/>
シンプルなフェード効果
左右へのスライド
上下へのスライド
3D回転エフェクト
波形アニメーション
歪みエフェクト
ディゾルブ効果
ピクセル単位のディゾルブ
円形トランジション
モーフィング効果
グリッチエフェクト
オプション | 型 | デフォルト | 説明 |
---|---|---|---|
container | string | HTMLElement | 必須 | カルーセルを表示するコンテナ |
images | string[] | [] | 表示する画像のURL配列 |
effect | string | 'fade' | 使用するトランジションエフェクト |
autoplay | boolean | false | 自動再生の有効/無効 |
interval | number | 3000 | 自動再生の間隔(ミリ秒) |
transitionDuration | number | 1000 | トランジションの長さ(ミリ秒) |
loop | boolean | true | 最後の画像の後に最初に戻るか |
showControls | boolean | true | ナビゲーションコントロールの表示 |
showIndicators | boolean | true | インジケーターの表示 |
// 次の画像へ
carousel.next();
// 前の画像へ
carousel.previous();
// 特定のインデックスへ
carousel.goTo(2);
// 自動再生の開始/停止
carousel.play();
carousel.pause();
// エフェクトの変更
carousel.setEffect('wave');
// リサイズ
carousel.resize();
// 破棄
carousel.dispose();
// 画像変更時
carousel.on('change', (index) => {
console.log('Current image:', index);
});
// トランジション開始時
carousel.on('transitionStart', (from, to) => {
console.log(`Transitioning from ${from} to ${to}`);
});
// トランジション完了時
carousel.on('transitionEnd', (index) => {
console.log('Transition completed:', index);
});
// エラー時
carousel.on('error', (error) => {
console.error('Carousel error:', error);
});
独自のGLSLシェーダーを使用してカスタムエフェクトを作成できます。
import { createCustomEffect } from 'webgl-carousel';
const myEffect = createCustomEffect(
'myCustomEffect',
// Vertex shader (optional)
`
attribute vec2 aPosition;
attribute vec2 aTexCoord;
varying vec2 vTexCoord;
void main() {
gl_Position = vec4(aPosition, 0.0, 1.0);
vTexCoord = aTexCoord;
}
`,
// Fragment shader
`
precision mediump float;
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform float uProgress;
uniform vec2 uResolution;
varying vec2 vTexCoord;
void main() {
vec2 uv = vTexCoord;
// カスタムエフェクトロジック
float wave = sin(uv.y * 10.0 + uProgress * 3.14159) * 0.05;
vec2 distortedUV = vec2(uv.x + wave * uProgress, uv.y);
vec4 color0 = texture2D(uTexture0, distortedUV);
vec4 color1 = texture2D(uTexture1, uv);
gl_FragColor = mix(color0, color1, uProgress);
}
`
);
// カスタムエフェクトを登録
carousel.registerEffect(myEffect);
carousel.setEffect('myCustomEffect');