<div class="corner-toast-banner" id="cornerToastBanner">
<div class="toast-content">
<div class="toast-icon">🍪</div>
<div class="toast-text">
<h4>Cookie Notice</h4>
<p>We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.</p>
</div>
<div class="toast-actions">
<button class="btn-accept" onclick="acceptCookies()">Accept</button>
<button class="btn-decline" onclick="declineCookies()">Decline</button>
<button class="btn-close" onclick="closeBanner()" aria-label="Close">×</button>
</div>
</div>
</div>
.corner-toast-banner {
position: fixed;
top: 20px;
right: 20px;
max-width: 400px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
z-index: 10000;
transform: translateX(450px);
transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.corner-toast-banner.show {
transform: translateX(0);
}
.toast-content {
padding: 20px;
display: flex;
align-items: flex-start;
gap: 15px;
}
.toast-icon {
font-size: 24px;
flex-shrink: 0;
}
.toast-text h4 {
margin: 0 0 8px 0;
color: white;
font-size: 16px;
font-weight: 600;
}
.toast-text p {
margin: 0;
color: rgba(255, 255, 255, 0.9);
font-size: 14px;
line-height: 1.4;
}
.toast-actions {
display: flex;
flex-direction: column;
gap: 8px;
flex-shrink: 0;
}
.toast-actions button {
padding: 8px 16px;
border: none;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.btn-accept {
background: rgba(255, 255, 255, 0.9);
color: #333;
}
.btn-accept:hover {
background: white;
transform: translateY(-1px);
}
.btn-decline {
background: rgba(255, 255, 255, 0.1);
color: white;
border: 1px solid rgba(255, 255, 255, 0.3);
}
.btn-decline:hover {
background: rgba(255, 255, 255, 0.2);
}
.btn-close {
background: transparent;
color: rgba(255, 255, 255, 0.7);
font-size: 18px;
width: 24px;
height: 24px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
.btn-close:hover {
color: white;
background: rgba(255, 255, 255, 0.1);
}
@media (max-width: 768px) {
.corner-toast-banner {
top: 10px;
right: 10px;
left: 10px;
max-width: none;
transform: translateY(-100vh);
}
.corner-toast-banner.show {
transform: translateY(0);
}
.toast-content {
flex-direction: column;
gap: 15px;
}
.toast-actions {
flex-direction: row;
justify-content: space-between;
width: 100%;
}
}
// Corner Toast Cookie Banner JavaScript
class CornerToastCookieBanner {
constructor(options = {}) {
this.options = {
position: 'top-right',
autoShow: true,
showDelay: 1000,
autoClose: false,
closeDelay: 10000,
storageKey: 'cookie_consent_toast',
onAccept: () => {},
onDecline: () => {},
onClose: () => {},
...options
};
this.banner = null;
this.init();
}
init() {
if (this.hasConsent()) return;
this.createBanner();
if (this.options.autoShow) {
setTimeout(() => this.show(), this.options.showDelay);
}
if (this.options.autoClose) {
setTimeout(() => this.close(), this.options.closeDelay);
}
}
createBanner() {
this.banner = document.getElementById('cornerToastBanner');
if (!this.banner) {
console.warn('Corner toast banner element not found');
return;
}
this.setPosition();
this.attachEvents();
}
setPosition() {
const positions = {
'top-left': { top: '20px', left: '20px', right: 'auto' },
'top-right': { top: '20px', right: '20px', left: 'auto' },
'bottom-left': { bottom: '20px', left: '20px', right: 'auto', top: 'auto' },
'bottom-right': { bottom: '20px', right: '20px', left: 'auto', top: 'auto' }
};
const pos = positions[this.options.position] || positions['top-right'];
Object.assign(this.banner.style, pos);
}
attachEvents() {
// Events are handled by global functions for simplicity
window.acceptCookies = () => this.accept();
window.declineCookies = () => this.decline();
window.closeBanner = () => this.close();
}
show() {
if (this.banner) {
this.banner.classList.add('show');
}
}
hide() {
if (this.banner) {
this.banner.classList.remove('show');
}
}
accept() {
this.setConsent('accepted');
this.options.onAccept();
this.close();
}
decline() {
this.setConsent('declined');
this.options.onDecline();
this.close();
}
close() {
this.hide();
this.options.onClose();
setTimeout(() => {
if (this.banner) {
this.banner.style.display = 'none';
}
}, 400);
}
setConsent(value) {
localStorage.setItem(this.options.storageKey, JSON.stringify({
consent: value,
timestamp: new Date().toISOString()
}));
}
hasConsent() {
const stored = localStorage.getItem(this.options.storageKey);
return stored !== null;
}
reset() {
localStorage.removeItem(this.options.storageKey);
if (this.banner) {
this.banner.style.display = 'block';
this.show();
}
}
}
// Initialize the banner
document.addEventListener('DOMContentLoaded', () => {
const cookieBanner = new CornerToastCookieBanner({
position: 'top-right',
autoShow: true,
showDelay: 1000,
onAccept: () => {
console.log('Cookies accepted');
// Enable analytics, tracking, etc.
},
onDecline: () => {
console.log('Cookies declined');
// Disable non-essential cookies
}
});
});