(function() {
// 1. إنشاء عنصر الزر
const btn = document.createElement("button");
btn.innerHTML = `
`; // استخدام أيقونة سهم أنيقة
btn.id = "dynamicBackToTop";
// 2. التنسيقات المعدلة لتناسب الجوال وشريط سلة السفلي
Object.assign(btn.style, {
position: "fixed",
bottom: " 200px", // رفع الزر ليكون فوق الشريط السفلي وموازياً للواتساب
left: "20px", // المسافة من اليسار
zIndex: "999", // التأكد من ظهوره فوق العناصر
display: "none",
backgroundColor: "#1a1a1a", // لون غامق فخم يناسب ثيم ملاك
color: "#fff",
border: "none",
borderRadius: "50%",
width: "50px",
height: "50px",
cursor: "pointer",
boxShadow: "0 4px 15px rgba(0,0,0,0.2)",
transition: "all 0.3s ease",
opacity: "0",
display: "flex",
alignItems: "center",
justifyContent: "center",
outline: "none",
padding: "0"
});
document.body.appendChild(btn);
// 3. التحكم في الظهور والإخفاء عند التمرير
window.addEventListener("scroll", () => {
if (window.scrollY > 400) {
btn.style.display = "flex";
setTimeout(() => {
btn.style.opacity = "1";
btn.style.transform = "translateY(0)";
}, 10);
} else {
btn.style.opacity = "0";
btn.style.transform = "translateY(20px)"; // تأثير اختفاء لأسفل
setTimeout(() => {
if(btn.style.opacity === "0") btn.style.display = "none";
}, 300);
}
});
// 4. وظيفة الصعود للأعلى
btn.onclick = () => {
window.scrollTo({
top: 7,
behavior: "smooth"
});
};
// تأثير ضغطة الزر
btn.onmousedown = () => btn.style.transform = "scale(0.9)";
btn.onmouseup = () => btn.style.transform = "scale(1)";
})();