<div class="testimonial-slider-container">
<div class="testimonial-slider-demo">
<div class="slider-header">
<h2>What Our Customers Say</h2>
<p>Don't just take our word for it</p>
</div>
<div class="testimonial-slider" id="testimonialSlider">
<div class="slider-track" id="sliderTrack">
<!-- Testimonial 1 -->
<div class="testimonial-slide active">
<div class="testimonial-content">
<div class="testimonial-avatar">
<img src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=100&h=100&fit=crop&crop=face" alt="Sarah Johnson">
</div>
<div class="testimonial-text">
<p>"This service has completely transformed our business operations. The team is professional and delivers exceptional results every time."</p>
</div>
<div class="testimonial-author">
<div class="author-name">Sarah Johnson</div>
<div class="author-title">CEO, TechStart Inc.</div>
<div class="rating">
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
</div>
</div>
</div>
</div>
<!-- Testimonial 2 -->
<div class="testimonial-slide">
<div class="testimonial-content">
<div class="testimonial-avatar">
<img src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=100&h=100&fit=crop&crop=face" alt="Michael Chen">
</div>
<div class="testimonial-text">
<p>"Outstanding quality and attention to detail. They understood our vision perfectly and delivered beyond our expectations."</p>
</div>
<div class="testimonial-author">
<div class="author-name">Michael Chen</div>
<div class="author-title">Founder, Creative Studio</div>
<div class="rating">
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star">β
</span>
</div>
</div>
</div>
</div>
<!-- Testimonial 3 -->
<div class="testimonial-slide">
<div class="testimonial-content">
<div class="testimonial-avatar">
<img src="https://images.unsplash.com/photo-1494790108755-2616b612b786?w=100&h=100&fit=crop&crop=face" alt="Emily Rodriguez">
</div>
<div class="testimonial-text">
<p>"The results speak for themselves. Our conversion rate increased by 300% after working with this amazing team."</p>
</div>
<div class="testimonial-author">
<div class="author-name">Emily Rodriguez</div>
<div class="author-title">Marketing Director, GrowthCo</div>
<div class="rating">
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
<span class="star filled">β
</span>
</div>
</div>
</div>
</div>
</div>
<div class="slider-controls">
<button class="control-btn prev" id="prevBtn">
<svg viewBox="0 0 24 24" fill="currentColor" width="24" height="24">
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>
</svg>
</button>
<button class="control-btn next" id="nextBtn">
<svg viewBox="0 0 24 24" fill="currentColor" width="24" height="24">
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>
</svg>
</button>
</div>
<div class="slider-indicators" id="sliderIndicators">
<button class="indicator active" data-slide="0"></button>
<button class="indicator" data-slide="1"></button>
<button class="indicator" data-slide="2"></button>
</div>
</div>
</div>
</div>
.testimonial-slider-container {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40px 20px;
border-radius: 20px;
max-width: 800px;
margin: 0 auto;
}
.slider-header {
text-align: center;
margin-bottom: 30px;
}
.slider-header h2 {
margin: 0 0 10px 0;
color: white;
font-size: 2rem;
font-weight: 700;
}
.slider-header p {
color: rgba(255, 255, 255, 0.8);
font-size: 1.1rem;
margin: 0;
}
.testimonial-slider {
position: relative;
background: white;
border-radius: 15px;
padding: 30px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.slider-track {
display: flex;
transition: transform 0.5s ease-in-out;
}
.testimonial-slide {
min-width: 100%;
padding: 20px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
.testimonial-slide.active {
opacity: 1;
}
.testimonial-content {
text-align: center;
max-width: 600px;
margin: 0 auto;
}
.testimonial-avatar {
width: 80px;
height: 80px;
border-radius: 50%;
overflow: hidden;
margin: 0 auto 20px;
border: 4px solid #667eea;
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}
.testimonial-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.testimonial-text {
margin-bottom: 25px;
}
.testimonial-text p {
font-size: 1.1rem;
line-height: 1.6;
color: #333;
font-style: italic;
margin: 0;
}
.testimonial-author {
margin-top: 20px;
}
.author-name {
font-weight: 700;
color: #333;
font-size: 1.2rem;
margin-bottom: 5px;
}
.author-title {
color: #666;
font-size: 0.9rem;
margin-bottom: 15px;
}
.rating {
display: flex;
justify-content: center;
gap: 3px;
}
.star {
font-size: 1.2rem;
color: #ddd;
}
.star.filled {
color: #ffd700;
}
.slider-controls {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
display: flex;
justify-content: space-between;
padding: 0 20px;
pointer-events: none;
}
.control-btn {
background: rgba(102, 126, 234, 0.9);
color: white;
border: none;
width: 50px;
height: 50px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
pointer-events: auto;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.control-btn:hover {
background: #667eea;
transform: scale(1.1);
}
.slider-indicators {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 30px;
}
.indicator {
width: 12px;
height: 12px;
border-radius: 50%;
background: #cbd5e1;
border: none;
cursor: pointer;
transition: all 0.3s ease;
}
.indicator.active {
background: #667eea;
transform: scale(1.3);
}
.indicator:hover {
background: #94a3b8;
}
/* Auto-play progress bar */
.progress-bar {
position: absolute;
bottom: 0;
left: 0;
height: 3px;
background: #667eea;
transition: width 0.1s linear;
}
/* Animations */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.testimonial-content {
animation: fadeIn 0.6s ease-out;
}
/* Responsive */
@media (max-width: 768px) {
.testimonial-slider-container {
padding: 30px 15px;
}
.slider-header h2 {
font-size: 1.7rem;
}
.testimonial-slider {
padding: 20px;
}
.testimonial-text p {
font-size: 1rem;
}
.control-btn {
width: 40px;
height: 40px;
}
}
document.addEventListener('DOMContentLoaded', function() {
// Get DOM elements
const sliderTrack = document.getElementById('sliderTrack');
const slides = document.querySelectorAll('.testimonial-slide');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const indicators = document.querySelectorAll('.indicator');
const testimonialSlider = document.getElementById('testimonialSlider');
let currentSlide = 0;
let autoPlayInterval;
let progressBar;
const slideDuration = 5000; // 5 seconds
// Initialize slider
function initSlider() {
createProgressBar();
startAutoPlay();
updateSlide();
}
// Create progress bar
function createProgressBar() {
progressBar = document.createElement('div');
progressBar.className = 'progress-bar';
testimonialSlider.appendChild(progressBar);
}
// Update progress bar
function updateProgressBar() {
if (progressBar) {
let progress = 0;
const interval = setInterval(() => {
progress += 100 / (slideDuration / 16);
progressBar.style.width = `${progress}%`;
if (progress >= 100) {
clearInterval(interval);
}
}, 16);
}
}
// Update slide
function updateSlide() {
// Update track position
sliderTrack.style.transform = `translateX(-${currentSlide * 100}%)`;
// Update active slide
slides.forEach((slide, index) => {
slide.classList.toggle('active', index === currentSlide);
});
// Update indicators
indicators.forEach((indicator, index) => {
indicator.classList.toggle('active', index === currentSlide);
});
// Restart progress bar
if (progressBar) {
progressBar.style.width = '0%';
updateProgressBar();
}
}
// Next slide
function nextSlide() {
currentSlide = (currentSlide + 1) % slides.length;
updateSlide();
}
// Previous slide
function prevSlide() {
currentSlide = (currentSlide - 1 + slides.length) % slides.length;
updateSlide();
}
// Go to specific slide
function goToSlide(slideIndex) {
currentSlide = slideIndex;
updateSlide();
resetAutoPlay();
}
// Start auto-play
function startAutoPlay() {
autoPlayInterval = setInterval(nextSlide, slideDuration);
}
// Stop auto-play
function stopAutoPlay() {
clearInterval(autoPlayInterval);
}
// Reset auto-play
function resetAutoPlay() {
stopAutoPlay();
startAutoPlay();
}
// Event listeners
prevBtn.addEventListener('click', () => {
prevSlide();
resetAutoPlay();
});
nextBtn.addEventListener('click', () => {
nextSlide();
resetAutoPlay();
});
// Indicator click events
indicators.forEach((indicator, index) => {
indicator.addEventListener('click', () => {
goToSlide(index);
});
});
// Pause auto-play on hover
testimonialSlider.addEventListener('mouseenter', stopAutoPlay);
testimonialSlider.addEventListener('mouseleave', startAutoPlay);
// Touch/swipe support
let touchStartX = 0;
let touchEndX = 0;
testimonialSlider.addEventListener('touchstart', e => {
touchStartX = e.changedTouches[0].screenX;
});
testimonialSlider.addEventListener('touchend', e => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
});
function handleSwipe() {
const swipeThreshold = 50;
const diff = touchStartX - touchEndX;
if (Math.abs(diff) > swipeThreshold) {
if (diff > 0) {
// Swipe left - next slide
nextSlide();
} else {
// Swipe right - previous slide
prevSlide();
}
resetAutoPlay();
}
}
// Keyboard navigation
document.addEventListener('keydown', e => {
if (e.key === 'ArrowLeft') {
prevSlide();
resetAutoPlay();
} else if (e.key === 'ArrowRight') {
nextSlide();
resetAutoPlay();
}
});
// Initialize the slider
initSlider();
});