// 组织建设页面脚本 $(document).ready(function() { // 党委荣誉点击放大 $('.org-honor-item').on('click', function() { const imgSrc = $(this).find('img').attr('src'); // 可以添加图片预览/灯箱功能 const lightbox = $('#lightbox'); const lightboxImg = lightbox.find('.lightbox-img'); // 设置预览图地址并显示灯箱 lightboxImg.attr('src', imgSrc); lightbox.css('display', 'flex'); // 点击“关闭按钮”隐藏灯箱 lightbox.find('.lightbox-close').on('click', function() { lightbox.hide(); }); // 点击“遮罩层”也隐藏灯箱(点击非图片区域时关闭) lightbox.on('click', function(e) { if (e.target === this) { lightbox.hide(); } }); }); // 文件点击事件 /* $('.file-item').on('click', function() { const fileTitle = $(this).find('.file-title').text(); alert('打开文件:' + fileTitle); // 这里可以添加实际的文件打开或下载逻辑 }); */ // 党委活动堆叠轮播 let currentSlide = 0; const slides = $('.activity-slide'); const totalSlides = slides.length; function updateSlides() { slides.removeClass('active prev next prev-2 next-2'); // 当前图片(中间) slides.eq(currentSlide).addClass('active'); // 左侧第1张 const prevIndex = currentSlide === 0 ? totalSlides - 1 : currentSlide - 1; slides.eq(prevIndex).addClass('prev'); // 左侧第2张 const prev2Index = prevIndex === 0 ? totalSlides - 1 : prevIndex - 1; slides.eq(prev2Index).addClass('prev-2'); // 右侧第1张 const nextIndex = currentSlide === totalSlides - 1 ? 0 : currentSlide + 1; slides.eq(nextIndex).addClass('next'); // 右侧第2张 const next2Index = nextIndex === totalSlides - 1 ? 0 : nextIndex + 1; slides.eq(next2Index).addClass('next-2'); // 调试信息 console.log('当前幻灯片:', currentSlide); console.log('总幻灯片数:', totalSlides); console.log('显示的图片索引:', [prev2Index, prevIndex, currentSlide, nextIndex, next2Index]); // 指示器已移除,无需更新 } function goToSlide(index) { if (index < 0) { currentSlide = totalSlides - 1; } else if (index >= totalSlides) { currentSlide = 0; } else { currentSlide = index; } updateSlides(); } // 初始化 updateSlides(); // 上一张 $('#activityPrev').on('click', function() { goToSlide(currentSlide - 1); }); // 下一张 $('#activityNext').on('click', function() { goToSlide(currentSlide + 1); }); // 指示器已移除,无需处理点击事件 // 自动播放(可选) let autoplayInterval; function startAutoplay() { autoplayInterval = setInterval(function() { goToSlide(currentSlide + 1); }, 5000); // 每5秒切换一次 } function stopAutoplay() { clearInterval(autoplayInterval); } // 鼠标悬停时暂停自动播放 $('.activities-slider-container').on('mouseenter', stopAutoplay); $('.activities-slider-container').on('mouseleave', startAutoplay); // 启动自动播放 startAutoplay(); // 触摸滑动支持(移动端) let touchStartX = 0; let touchEndX = 0; $('.activities-slider').on('touchstart', function(e) { touchStartX = e.touches[0].clientX; }); $('.activities-slider').on('touchend', function(e) { touchEndX = e.changedTouches[0].clientX; handleSwipe(); }); function handleSwipe() { if (touchEndX < touchStartX - 50) { // 向左滑动 goToSlide(currentSlide + 1); } if (touchEndX > touchStartX + 50) { // 向右滑动 goToSlide(currentSlide - 1); } } // 点击左右图片切换 $(document).on('click', '.activity-slide.prev', function() { goToSlide(currentSlide - 1); }); $(document).on('click', '.activity-slide.prev-2', function() { goToSlide(currentSlide - 2); }); $(document).on('click', '.activity-slide.next', function() { goToSlide(currentSlide + 1); }); $(document).on('click', '.activity-slide.next-2', function() { goToSlide(currentSlide + 2); }); // 点击当前图片查看大图 $(document).on('click', '.activity-slide.active', function() { const imgSrc = $(this).find('img').attr('src'); // 可以添加图片预览/灯箱功能 const lightbox = $('#lightbox'); const lightboxImg = lightbox.find('.lightbox-img'); // 设置预览图地址并显示灯箱 lightboxImg.attr('src', imgSrc); lightbox.css('display', 'flex'); // 点击“关闭按钮”隐藏灯箱 lightbox.find('.lightbox-close').on('click', function() { lightbox.hide(); }); // 点击“遮罩层”也隐藏灯箱(点击非图片区域时关闭) lightbox.on('click', function(e) { if (e.target === this) { lightbox.hide(); } }); }); // 滚动动画 function checkScroll() { $('.org-structure-section, .party-honors-section, .study-files-section, .party-activities-section').each(function() { const elementTop = $(this).offset().top; const windowBottom = $(window).scrollTop() + $(window).height(); if (elementTop < windowBottom - 100) { $(this).css({ 'opacity': '1', 'transform': 'translateY(0)' }); } }); } // 初始化滚动动画 $('.org-structure-section, .party-honors-section, .study-files-section, .party-activities-section').css({ 'opacity': '0', 'transform': 'translateY(30px)', 'transition': 'all 0.6s ease' }); // 监听滚动 $(window).on('scroll', checkScroll); checkScroll(); // 页面加载时检查一次 // 返回顶部按钮 $('#backToTop').on('click', function() { $('html, body').animate({ scrollTop: 0 }, 600); }); // 显示/隐藏返回顶部按钮 $(window).on('scroll', function() { if ($(this).scrollTop() > 300) { $('#backToTop').fadeIn(); } else { $('#backToTop').fadeOut(); } }); });