Files
smartsoltech_site/smartsoltech/static/assets/js/modern-scripts.js
2025-11-25 12:39:50 +09:00

110 lines
3.9 KiB
JavaScript

// Modern Scripts for SmartSolTech Website
document.addEventListener('DOMContentLoaded', function() {
console.log('SmartSolTech: DOM loaded, initializing...');
// Hide loading screen
const loadingScreen = document.getElementById('loading-screen');
if (loadingScreen) {
console.log('SmartSolTech: Loading screen found, hiding...');
setTimeout(() => {
loadingScreen.style.opacity = '0';
loadingScreen.style.pointerEvents = 'none';
setTimeout(() => {
// Полностью удаляем элемент из DOM
if (loadingScreen.parentNode) {
loadingScreen.parentNode.removeChild(loadingScreen);
console.log('SmartSolTech: Loading screen completely removed from DOM');
}
}, 300);
}, 200); // Уменьшили время ожидания до 200ms
} else {
console.log('SmartSolTech: Loading screen not found');
}
// Theme Toggle Functionality
const themeToggle = document.getElementById('theme-toggle');
const html = document.documentElement;
if (themeToggle) {
// Check for saved theme preference
const currentTheme = localStorage.getItem('theme') || 'light';
html.setAttribute('data-theme', currentTheme);
updateThemeIcon(currentTheme);
themeToggle.addEventListener('click', function() {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
// Add animation
this.style.transform = 'scale(0.8)';
setTimeout(() => {
this.style.transform = 'scale(1)';
}, 150);
});
}
function updateThemeIcon(theme) {
if (!themeToggle) return;
const icon = themeToggle.querySelector('i');
if (icon) {
if (theme === 'dark') {
icon.className = 'fas fa-sun';
themeToggle.setAttribute('aria-label', 'Переключить на светлую тему');
} else {
icon.className = 'fas fa-moon';
themeToggle.setAttribute('aria-label', 'Переключить на темную тему');
}
}
}
// Navbar scroll behavior
const navbar = document.querySelector('.navbar-modern');
if (navbar) {
window.addEventListener('scroll', function() {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const target = document.querySelector(this.getAttribute('href'));
if (target) {
e.preventDefault();
target.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe cards and service items
document.querySelectorAll('.card-modern, .service-card, .step-card').forEach(card => {
observer.observe(card);
});
console.log('SmartSolTech: All scripts loaded successfully');
});