CSNET's picture
ทำแอพ HTML5 ภาษาไทย โดยมี module ดังนี้
df62a7a verified
Raw History Blame Contribute Delete
5.18 kB
class NavbarCustom extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.navbar {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 16px 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.navbar-container {
max-width: 480px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
}
.logo {
color: white;
font-size: 24px;
font-weight: bold;
text-decoration: none;
display: flex;
align-items: center;
}
.logo-icon {
width: 32px;
height: 32px;
margin-right: 8px;
background: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.notification-btn {
background: rgba(255, 255, 255, 0.2);
border: none;
border-radius: 50%;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
}
.notification-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: scale(1.05);
}
.notification-badge {
position: absolute;
top: -4px;
right: -4px;
background: #ef4444;
color: white;
border-radius: 50%;
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
font-weight: bold;
}
</style>
<nav class="navbar">
<div class="navbar-container">
<a href="#dashboard" class="logo">
<div class="logo-icon">
<span style="color: #667eea;">💗</span>
</div>
<span>ชีพจร</span>
</a>
<button class="notification-btn" onclick="showNotifications()">
<i data-feather="bell" style="width: 20px; height: 20px; color: white;"></i>
<span class="notification-badge">3</span>
</button>
</div>
</nav>
`;
}
}
customElements.define('nav-custom', NavbarCustom);
function showNotifications() {
// Create notification modal
const modal = document.createElement('div');
modal.className = 'modal';
modal.innerHTML = `
<div class="modal-content">
<h2 class="text-xl font-bold mb-4">การแจ้งเตือน</h2>
<div class="space-y-3">
<div class="p-3 bg-red-50 rounded-lg border-l-4 border-red-500">
<div class="font-semibold text-red-800">คำเตือน PM2.5</div>
<div class="text-sm text-red-600">ค่า PM2.5 สูงกว่ามาตรฐาน ควรหลีกเลี่ยงการออกกำลังกายกลางแจ้ง</div>
</div>
<div class="p-3 bg-orange-50 rounded-lg border-l-4 border-orange-500">
<div class="font-semibold text-orange-800">แจ้งเตือนออฟฟิศ</div>
<div class="text-sm text-orange-600">นั่งนิ่งมา 60 นาทีแล้ว ควรลุกขึ้นเดิน</div>
</div>
<div class="p-3 bg-blue-50 rounded-lg border-l-4 border-blue-500">
<div class="font-semibold text-blue-800">เวลาทานยา</div>
<div class="text-sm text-blue-600">ถึงเวลาทานวิตามินประจำวันแล้ว</div>
</div>
</div>
<button class="w-full mt-4 bg-indigo-600 text-white rounded-lg py-2 font-semibold hover:bg-indigo-700 transition" onclick="this.closest('.modal').remove()">
ปิด
</button>
</div>
`;
document.body.appendChild(modal);
// Close modal when clicking outside
modal.addEventListener('click', function(e) {
if (e.target === modal) {
modal.remove();
}
});
}