script.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // 导航栏滚动效果
  2. window.addEventListener('scroll', () => {
  3. const header = document.querySelector('.header');
  4. if (window.scrollY > 50) {
  5. header.style.backgroundColor = 'rgba(255, 255, 255, 0.95)';
  6. } else {
  7. header.style.backgroundColor = '#fff';
  8. }
  9. });
  10. // 平滑滚动
  11. document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  12. anchor.addEventListener('click', function (e) {
  13. e.preventDefault();
  14. const target = document.querySelector(this.getAttribute('href'));
  15. if (target) {
  16. target.scrollIntoView({
  17. behavior: 'smooth',
  18. block: 'start'
  19. });
  20. }
  21. });
  22. });
  23. // 表单提交处理
  24. const contactForm = document.querySelector('.contact-form');
  25. if (contactForm) {
  26. contactForm.addEventListener('submit', (e) => {
  27. e.preventDefault();
  28. // 获取表单数据
  29. const formData = new FormData(contactForm);
  30. const data = Object.fromEntries(formData);
  31. // 这里可以添加表单验证逻辑
  32. // 模拟表单提交
  33. alert('感谢您的留言!我们会尽快与您联系。');
  34. contactForm.reset();
  35. });
  36. }
  37. // 价格方案卡片悬停效果
  38. const pricingCards = document.querySelectorAll('.pricing-card');
  39. pricingCards.forEach(card => {
  40. card.addEventListener('mouseenter', () => {
  41. if (!card.classList.contains('featured')) {
  42. card.style.transform = 'translateY(-10px)';
  43. }
  44. });
  45. card.addEventListener('mouseleave', () => {
  46. if (!card.classList.contains('featured')) {
  47. card.style.transform = 'translateY(0)';
  48. }
  49. });
  50. });
  51. // 添加页面加载动画
  52. document.addEventListener('DOMContentLoaded', () => {
  53. const elements = document.querySelectorAll('.hero-content, .feature-card, .security-content, .pricing-card');
  54. elements.forEach((element, index) => {
  55. setTimeout(() => {
  56. element.style.opacity = '1';
  57. element.style.transform = 'translateY(0)';
  58. }, index * 200);
  59. });
  60. });
  61. // 初始化页面元素的样式
  62. const initElements = () => {
  63. const elements = document.querySelectorAll('.hero-content, .feature-card, .security-content, .pricing-card');
  64. elements.forEach(element => {
  65. element.style.opacity = '0';
  66. element.style.transform = 'translateY(20px)';
  67. element.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
  68. });
  69. };
  70. // 页面加载时初始化
  71. initElements();