// 科研项目页面脚本 $(document).ready(function() { // 筛选按钮功能 $('.filter-btn').on('click', function() { $('.filter-btn').removeClass('active'); $(this).addClass('active'); const filterType = $(this).data('filter'); if (filterType === 'all') { $('.project-card').fadeIn(300); } else { $('.project-card').each(function() { if ($(this).data('level') === filterType) { $(this).fadeIn(300); } else { $(this).fadeOut(300); } }); } }); // 搜索功能 $('#projectSearch').on('input', function() { const searchTerm = $(this).val().toLowerCase(); $('.project-card').each(function() { const title = $(this).find('.project-title').text().toLowerCase(); const desc = $(this).find('.project-desc').text().toLowerCase(); const tags = $(this).find('.project-tags').text().toLowerCase(); if (title.includes(searchTerm) || desc.includes(searchTerm) || tags.includes(searchTerm)) { $(this).fadeIn(300); } else { $(this).fadeOut(300); } }); }); // 项目卡片点击 $('.project-card').on('click', function() { const projectTitle = $(this).find('.project-title').text(); console.log('查看项目详情:' + projectTitle); // 可以跳转到详情页 // window.location.href = 'project-detail.html?id=xxx'; }); // 分页功能 /* let currentPage = 1; const totalPages = 3; // 总页数,实际应该从后端获取 */ // 更新分页状态 /* function updatePagination(page, shouldScroll = true) { currentPage = page; // 更新页码激活状态 $('.pagination-link').removeClass('active'); $(`.pagination-link[data-page="${page}"]`).addClass('active'); // 更新上一页/下一页按钮状态 if (currentPage <= 1) { $('.pagination-link.prev').addClass('disabled'); } else { $('.pagination-link.prev').removeClass('disabled'); } if (currentPage >= totalPages) { $('.pagination-link.next').addClass('disabled'); } else { $('.pagination-link.next').removeClass('disabled'); } // 只有点击时才滚动到列表顶部 if (shouldScroll) { $('html, body').animate({ scrollTop: $('.projects-grid').offset().top - 120 }, 500); } // 这里应该通过AJAX加载对应页的数据 console.log('切换到第', page, '页'); } */ // 分页点击事件 /* $('.pagination-link').on('click', function(e) { e.preventDefault(); if ($(this).hasClass('disabled') || $(this).hasClass('active')) { return; } const page = $(this).data('page'); if (page === 'prev') { if (currentPage > 1) { updatePagination(currentPage - 1, true); } } else if (page === 'next') { if (currentPage < totalPages) { updatePagination(currentPage + 1, true); } } else { updatePagination(page, true); } }); */ // 初始化分页状态(不触发滚动) /* if ($('.pagination-link').length > 0) { updatePagination(currentPage, false); } */ // 滚动动画 function checkScroll() { $('.project-card').each(function(index) { const elementTop = $(this).offset().top; const windowBottom = $(window).scrollTop() + $(window).height(); if (elementTop < windowBottom - 50) { setTimeout(() => { $(this).css({ 'opacity': '1', 'transform': 'translateY(0)' }); }, index * 50); } }); } // 初始化动画 $('.project-card').css({ 'opacity': '0', 'transform': 'translateY(20px)', 'transition': 'all 0.5s ease' }); $(window).on('scroll', checkScroll); checkScroll(); });