jaysalvat/vegas
Vegas is a jQuery plugin for creating fullscreen backgrounds and slideshow backdrops. Add images, videos, overlays, and transitions to any page element with simple options and events—ideal for hero sections, landing pages, and ambient site-wide backgrounds.
Installation Add the package via npm (if using Laravel Mix/Webpack) or include via CDN:
npm install jquery-vegas
Or via CDN in a Blade template:
<script src="https://cdn.jsdelivr.net/npm/jquery-vegas@2.0.7/dist/vegas.min.js"></script>
Basic Initialization Include jQuery/Zepto and Vegas in your layout:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-vegas@2.0.7/dist/vegas.min.js"></script>
First Use Case: Static Background Apply a static background to a DOM element:
$(document).ready(function() {
$('#hero-section').vegas({
slides: [
{ src: '/images/background1.jpg' }
]
});
});
<div id="hero-section" style="width: 100%; height: 500px;"></div>
Slideshow Integration Rotate images with transitions:
$('#slideshow').vegas({
slides: [
{ src: '/images/slide1.jpg', fade: 1000 },
{ src: '/images/slide2.jpg', fade: 1000 }
],
delay: 5000
});
Dynamic Content Loading Fetch slides via AJAX (e.g., from a Laravel API):
$.get('/api/slides', function(data) {
$('#gallery').vegas({
slides: data.map(slide => ({ src: slide.path }))
});
});
Responsive Design Use CSS to ensure Vegas adapts to viewport changes:
.vegas-container {
width: 100%;
height: 100vh;
}
Laravel Blade Integration Pass slides from a controller:
// routes/web.php
Route::get('/slideshow', [SlideController::class, 'show']);
// SlideController.php
public function show() {
$slides = Slide::all()->map(fn($slide) => ['src' => $slide->path]);
return view('slideshow', compact('slides'));
}
<!-- slideshow.blade.php -->
<script>
$(document).ready(function() {
$('#slideshow').vegas({ slides: @json($slides->toArray()) });
});
</script>
Event Handling Trigger actions on slide changes:
$('#slideshow').vegas({
slides: [...],
transition: 'fade',
onSlide: function() {
console.log('Slide changed!');
}
});
jQuery Dependency Vegas requires jQuery/Zepto. Ensure it’s loaded before Vegas:
<!-- WRONG: Vegas before jQuery -->
<script src="vegas.js"></script>
<script src="jquery.js"></script>
Image Paths
Use absolute paths (e.g., /images/slide.jpg) or Laravel’s asset() helper:
slides: [{ src: "{{ asset('images/slide.jpg') }}" }]
Z-Index Conflicts
Vegas overlays content. Explicitly set z-index for parent containers:
.vegas-container {
position: relative;
z-index: 1;
}
Mobile Performance
Large images may lag on mobile. Optimize with srcset or lazy-loading:
slides: [{ src: '/images/slide.jpg', data: { srcset: '/images/slide-webp.webp 1x' } }]
vegas is not a function (missing jQuery).Network tab).transition: 'crossfade' for smoother effects.Custom Transitions
Extend Vegas with custom animations via the transition option:
$.vegas.transition('myTransition', function($slide, $nextSlide, complete) {
// Custom animation logic
complete();
});
Laravel Service Provider Register Vegas globally for Blade directives (advanced):
// AppServiceProvider.php
View::composer('*', function($view) {
$view->with('vegasScripts', '<script src="/js/vegas.js"></script>');
});
Server-Side Slides Generate slides dynamically in Laravel (e.g., from a database):
$slides = Slide::where('active', 1)->get()->map(fn($slide) => [
'src' => $slide->path,
'data' => ['caption' => $slide->title]
]);
How can I help you explore Laravel packages today?