adsscale-pro / script.js
OShayL's picture
Manual changes saved
f30b63a verified
Raw History Blame Contribute Delete
11.5 kB
// AdsScalePro - Interactive Functionality
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
initializeCounters();
initializeAnimations();
initializeFormHandling();
});
document.addEventListener("DOMContentLoaded", () => {
feather.replace();
});
// Counter Animation
function initializeCounters() {
const counters = document.querySelectorAll('.counter');
const animateCounter = (counter) => {
const target = parseFloat(counter.getAttribute('data-target'));
const decimals = parseInt(counter.getAttribute('data-decimals')) || 0;
const duration = 2000; // 2 seconds
const start = performance.now();
function updateCounter(currentTime) {
const elapsed = currentTime - start;
const progress = Math.min(elapsed / duration, 1);
// Easing function for smooth animation
const easeOutCubic = 1 - Math.pow(1 - progress, 3);
const current = target * easeOutCubic;
counter.textContent = current.toFixed(decimals);
if (progress < 1) {
requestAnimationFrame(updateCounter);
} else {
counter.textContent = target.toFixed(decimals);
}
}
requestAnimationFrame(updateCounter);
};
// Create intersection observer for counters
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('animated')) {
entry.target.classList.add('animated');
animateCounter(entry.target);
}
});
}, {
threshold: 0.5
});
counters.forEach(counter => {
counterObserver.observe(counter);
});
}
// Initialize animations and interactions
function initializeAnimations() {
// Card hover effects (enhance CSS with JS)
const cards = document.querySelectorAll('.card-hover');
cards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-8px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Add stagger effect to service cards
const serviceCards = document.querySelectorAll('#services .glass');
serviceCards.forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
// Animate in when scrolled to
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, index * 100);
}
});
}, { threshold: 0.1 });
observer.observe(card);
});
// Progress bars animation
const progressBars = document.querySelectorAll('.progress > span');
progressBars.forEach(bar => {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
setTimeout(() => {
const value = bar.style.getPropertyValue('--value');
bar.style.width = value;
}, 500);
}
});
}, { threshold: 0.5 });
observer.observe(bar);
});
}
// Form handling
function initializeFormHandling() {
const contactForm = document.querySelector('#contact form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const formObject = {};
formData.forEach((value, key) => {
formObject[key] = value;
});
// Add visual feedback
const submitButton = this.querySelector('button[type="submit"]');
const originalText = submitButton.innerHTML;
submitButton.innerHTML = '<i data-feather="send"></i> Sending...';
submitButton.disabled = true;
// Simulate form submission (replace with actual form handling)
setTimeout(() => {
submitButton.innerHTML = '<i data-feather="check"></i> Message sent!';
submitButton.style.background = 'linear-gradient(135deg, #10b981 0%, #059669 100%)';
// Re-initialize feather icons
if (typeof feather !== 'undefined') {
feather.replace();
}
// Reset form after 2 seconds
setTimeout(() => {
this.reset();
submitButton.innerHTML = originalText;
submitButton.style.background = '';
submitButton.disabled = false;
if (typeof feather !== 'undefined') {
feather.replace();
}
}, 2000);
}, 1500);
});
}
}
// Button click tracking and interactions (excluding navbar buttons)
document.addEventListener('click', function(e) {
// Handle CTA button clicks (excluding navbar)
if (e.target.closest('.btn-primary') && !e.target.closest('header')) {
// Add visual feedback
const button = e.target.closest('.btn');
button.style.transform = 'scale(0.95)';
setTimeout(() => {
button.style.transform = 'scale(1)';
}, 150);
}
// Handle external links (excluding navbar and footer)
if (e.target.closest('a[target="_blank"]') && !e.target.closest('header') && !e.target.closest('footer')) {
const link = e.target.closest('a');
// Add subtle animation
link.style.transform = 'translateY(-2px)';
setTimeout(() => {
link.style.transform = 'translateY(0)';
}, 200);
}
});
// Lazy loading for images (if any are added later)
function initializeLazyLoading() {
const images = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
images.forEach(img => imageObserver.observe(img));
}
// Performance optimization: Throttle scroll events
function throttle(func, limit) {
let inThrottle;
return function() {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
}
}
// Apply throttling to scroll events
const throttledScrollHandler = throttle(function() {
// Any scroll-based animations can be added here
}, 100);
window.addEventListener('scroll', throttledScrollHandler);
// Infinite Reviews Scroll Animation
function initializeInfiniteReviewsScroll() {
const marqueeTrack = document.querySelector('.marquee-track');
if (!marqueeTrack) return;
// Create a more robust infinite scroll by cloning content
const originalContent = marqueeTrack.innerHTML;
marqueeTrack.innerHTML = originalContent + originalContent; // Duplicate content
let scrollPosition = 0;
const scrollSpeed = 0.5; // pixels per frame
let isScrolling = true;
function animateScroll() {
if (isScrolling) {
scrollPosition -= scrollSpeed;
// Reset when we've scrolled through one complete set
if (Math.abs(scrollPosition) >= marqueeTrack.scrollWidth / 2) {
scrollPosition = 0;
}
marqueeTrack.style.transform = `translateX(${scrollPosition}px)`;
}
requestAnimationFrame(animateScroll);
}
// Pause on hover
marqueeTrack.addEventListener('mouseenter', () => {
isScrolling = false;
});
marqueeTrack.addEventListener('mouseleave', () => {
isScrolling = true;
});
// Handle visibility change (pause when tab is not active)
document.addEventListener('visibilitychange', () => {
isScrolling = !document.hidden;
});
// Respect reduced motion preference
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
requestAnimationFrame(animateScroll);
}
}
// Enhanced scroll-to-top with smooth reveal
function initializeScrollToTopEnhanced() {
// Create scroll to top button if not exists
if (!document.querySelector('.scroll-to-top')) {
const scrollButton = document.createElement('button');
scrollButton.className = 'scroll-to-top fixed bottom-6 right-6 z-40 btn btn-primary rounded-full h-12 w-12 opacity-0 pointer-events-none transition-all duration-300 shadow-glow';
scrollButton.innerHTML = '<i data-feather="arrow-up"></i>';
scrollButton.setAttribute('aria-label', 'Scroll to top');
document.body.appendChild(scrollButton);
// Show/hide scroll to top button
const toggleScrollButton = () => {
if (window.pageYOffset > 300) {
scrollButton.style.opacity = '1';
scrollButton.style.pointerEvents = 'auto';
scrollButton.style.transform = 'scale(1)';
} else {
scrollButton.style.opacity = '0';
scrollButton.style.pointerEvents = 'none';
scrollButton.style.transform = 'scale(0.8)';
}
};
window.addEventListener('scroll', throttle(toggleScrollButton, 100));
// Scroll to top on click
scrollButton.addEventListener('click', function() {
this.style.transform = 'scale(0.9)';
setTimeout(() => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
this.style.transform = 'scale(1)';
}, 100);
});
// Re-initialize feather icons
if (typeof feather !== 'undefined') {
feather.replace();
}
}
}
// Add CSS class for reduced motion preference
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.body.classList.add('reduce-motion');
}
// Initialize additional features
document.addEventListener('DOMContentLoaded', function() {
initializeInfiniteReviewsScroll();
initializeScrollToTopEnhanced();
});
// Export functions for potential external use
window.AdsScalePro = {
initializeCounters,
initializeAnimations,
initializeFormHandling,
initializeInfiniteReviewsScroll,
initializeScrollToTopEnhanced
};