<div class="cookie-consent-demo">
<button class="show-banner-btn" id="showBannerBtn">Show Cookie Banner</button>
</div>
<div class="cookie-consent-banner" id="cookieConsentBanner">
<div class="banner-content">
<div class="banner-text">
<h4>We use cookies</h4>
<p>We use cookies to improve your experience and for marketing purposes. By continuing to use our site, you consent to our cookie policy.</p>
</div>
<div class="banner-actions">
<button class="btn btn-secondary" id="rejectCookies">Reject</button>
<button class="btn btn-primary" id="acceptCookies">Accept All</button>
<button class="btn btn-outline" id="customizeCookies">Customize</button>
</div>
</div>
<div class="customization-panel" id="customizationPanel">
<div class="panel-header">
<h4>Cookie Preferences</h4>
<button class="close-panel" id="closePanel">×</button>
</div>
<div class="panel-content">
<div class="cookie-option">
<div class="option-info">
<h5>Essential Cookies</h5>
<p>Required for the website to function properly</p>
</div>
<label class="switch">
<input type="checkbox" id="essentialCookies" checked disabled>
<span class="slider"></span>
</label>
</div>
<div class="cookie-option">
<div class="option-info">
<h5>Analytics Cookies</h5>
<p>Help us understand how visitors interact with our site</p>
</div>
<label class="switch">
<input type="checkbox" id="analyticsCookies" checked>
<span class="slider"></span>
</label>
</div>
<div class="cookie-option">
<div class="option-info">
<h5>Marketing Cookies</h5>
<p>Used to track visitors across websites for personalized ads</p>
</div>
<label class="switch">
<input type="checkbox" id="marketingCookies">
<span class="slider"></span>
</label>
</div>
</div>
<div class="panel-actions">
<button class="btn btn-primary" id="savePreferences">Save Preferences</button>
</div>
</div>
</div>
.cookie-consent-demo {
display: flex;
justify-content: center;
align-items: center;
min-height: 150px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 15px;
}
.show-banner-btn {
padding: 15px 30px;
background: rgba(255, 255, 255, 0.2);
color: white;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.show-banner-btn:hover {
background: rgba(255, 255, 255, 0.3);
border-color: rgba(255, 255, 255, 0.5);
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
.cookie-consent-banner {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: white;
box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
z-index: 10000;
transform: translateY(100%);
transition: transform 0.5s ease;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
overflow: hidden;
}
.cookie-consent-banner.visible {
transform: translateY(0);
}
.banner-content {
display: flex;
align-items: center;
padding: 25px 30px;
gap: 20px;
}
.banner-text {
flex: 1;
}
.banner-text h4 {
margin: 0 0 10px 0;
color: #333;
font-size: 1.2rem;
font-weight: 600;
}
.banner-text p {
margin: 0;
color: #666;
font-size: 0.95rem;
line-height: 1.5;
}
.banner-actions {
display: flex;
gap: 10px;
flex-shrink: 0;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 6px;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
background: #f1f5f9;
color: #666;
}
.btn-secondary:hover {
background: #e2e8f0;
transform: translateY(-2px);
}
.btn-outline {
background: transparent;
color: #667eea;
border: 2px solid #667eea;
}
.btn-outline:hover {
background: #667eea;
color: white;
transform: translateY(-2px);
}
.customization-panel {
background: #f8fafc;
border-top: 1px solid #e2e8f0;
padding: 25px 30px;
max-height: 0;
overflow: hidden;
transition: max-height 0.5s ease;
}
.customization-panel.expanded {
max-height: 500px;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.panel-header h4 {
margin: 0;
color: #333;
font-size: 1.2rem;
font-weight: 600;
}
.close-panel {
background: none;
border: none;
font-size: 24px;
color: #999;
cursor: pointer;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: all 0.2s ease;
}
.close-panel:hover {
background: #f1f5f9;
color: #333;
}
.cookie-option {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 0;
border-bottom: 1px solid #e2e8f0;
}
.cookie-option:last-child {
border-bottom: none;
}
.option-info h5 {
margin: 0 0 5px 0;
color: #333;
font-size: 1rem;
font-weight: 600;
}
.option-info p {
margin: 0;
color: #666;
font-size: 0.85rem;
}
/* Switch styles */
.switch {
position: relative;
display: inline-block;
width: 50px;
height: 24px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #cbd5e1;
transition: .4s;
border-radius: 24px;
}
.slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
input:checked + .slider:before {
transform: translateX(26px);
}
input:disabled + .slider {
opacity: 0.6;
cursor: not-allowed;
}
.panel-actions {
margin-top: 20px;
text-align: right;
}
/* Animations */
@keyframes slideInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.banner-content {
animation: slideInUp 0.6s ease-out;
}
/* Responsive */
@media (max-width: 768px) {
.banner-content {
flex-direction: column;
text-align: center;
gap: 15px;
}
.banner-actions {
width: 100%;
justify-content: center;
}
.btn {
padding: 8px 15px;
font-size: 0.85rem;
}
.cookie-option {
flex-direction: column;
align-items: flex-start;
gap: 15px;
}
.panel-actions {
text-align: center;
}
}
@media (max-width: 480px) {
.banner-content {
padding: 20px;
}
.customization-panel {
padding: 20px;
}
.btn {
flex: 1;
}
}
document.addEventListener('DOMContentLoaded', function() {
// Get DOM elements
const showBannerBtn = document.getElementById('showBannerBtn');
const cookieBanner = document.getElementById('cookieConsentBanner');
const acceptBtn = document.getElementById('acceptCookies');
const rejectBtn = document.getElementById('rejectCookies');
const customizeBtn = document.getElementById('customizeCookies');
const savePreferencesBtn = document.getElementById('savePreferences');
const closePanelBtn = document.getElementById('closePanel');
const customizationPanel = document.getElementById('customizationPanel');
// Show banner button event
showBannerBtn.addEventListener('click', function() {
cookieBanner.classList.add('visible');
});
// Accept all cookies
acceptBtn.addEventListener('click', function() {
setCookiePreference('all');
hideBanner();
});
// Reject non-essential cookies
rejectBtn.addEventListener('click', function() {
setCookiePreference('essential');
hideBanner();
});
// Customize cookies
customizeBtn.addEventListener('click', function() {
customizationPanel.classList.add('expanded');
});
// Close customization panel
closePanelBtn.addEventListener('click', function() {
customizationPanel.classList.remove('expanded');
});
// Save preferences
savePreferencesBtn.addEventListener('click', function() {
const analyticsChecked = document.getElementById('analyticsCookies').checked;
const marketingChecked = document.getElementById('marketingCookies').checked;
setCookiePreference({
essential: true,
analytics: analyticsChecked,
marketing: marketingChecked
});
customizationPanel.classList.remove('expanded');
hideBanner();
});
// Check if user has already made a choice
function checkCookieConsent() {
const consent = getCookie('cookie_consent');
if (!consent) {
// Show banner after a delay
setTimeout(() => {
cookieBanner.classList.add('visible');
}, 1000);
}
}
// Set cookie preference
function setCookiePreference(preference) {
let consentValue;
if (preference === 'all') {
consentValue = JSON.stringify({
essential: true,
analytics: true,
marketing: true,
timestamp: new Date().toISOString()
});
} else if (preference === 'essential') {
consentValue = JSON.stringify({
essential: true,
analytics: false,
marketing: false,
timestamp: new Date().toISOString()
});
} else {
consentValue = JSON.stringify({
essential: true,
analytics: preference.analytics,
marketing: preference.marketing,
timestamp: new Date().toISOString()
});
}
// Set cookie for 365 days
document.cookie = `cookie_consent=${consentValue}; path=/; max-age=${365 * 24 * 60 * 60}`;
// Log consent for analytics
console.log('Cookie consent set:', preference);
}
// Get cookie value
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
// Hide banner with animation
function hideBanner() {
cookieBanner.style.transform = 'translateY(100%)';
setTimeout(() => {
cookieBanner.classList.remove('visible');
}, 500);
}
// Initialize
checkCookieConsent();
});