مكتبة الأكواد البرمجية

شريط تنقل متجاوب

كود لإنشاء شريط تنقل متجاوب مع تأثيرات عند التمرير

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: #6c63ff;
  position: fixed;
  top: 0;
  width: 100%;
  transition: background 0.3s;
}

.navbar.scrolled {
  background: rgba(108, 99, 255, 0.9);
  backdrop-filter: blur(10px);
}

نافذة حوار تفاعلية

كود لإنشاء نافذة حوار تفاعلية باستخدام HTML و JavaScript

<dialog id="myDialog">
  <h2>نافذة حوار</h2>
  <p>هذه نافذة حوار تفاعلية</p>
  <button onclick="document.getElementById('myDialog').close()">إغلاق</button>
</dialog>

<button onclick="document.getElementById('myDialog').showModal()">فتح الحوار</button>

دالة جلب البيانات

دالة لجلب البيانات من API باستخدام JavaScript

async function fetchData(url) {
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    const data = await response.json();
    return data;
  } catch (error) {
    console.error('Error fetching data:', error);
    return null;
  }
}

// استخدام الدالة
const data = await fetchData('https://api.example.com/data');
console.log(data);

تصميم بطاقة منتج

كود لإنشاء بطاقة منتج بتصميم حديث وجذاب

.product-card {
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.product-info {
  padding: 20px;
}

.product-title {
  font-size: 1.2rem;
  margin-bottom: 10px;
  color: #333;
}

.product-price {
  font-size: 1.1rem;
  color: #6c63ff;
  font-weight: bold;
}