// 新闻资讯页面脚本 $(document).ready(function() { // 标签切换 /* $('.tab-menu-item').on('click', function(e) { e.preventDefault(); // 更新激活状态 $('.tab-menu-item').removeClass('active'); $(this).addClass('active'); // 获取分类 const category = $(this).data('category'); // 隐藏所有内容区域(只隐藏主内容区的列表和卡片,不隐藏tab菜单) $('.page-main [data-category]').hide(); // 显示对应分类的内容 $('.page-main [data-category="' + category + '"]').show(); // 重置分页到第1页 /* currentPage = 1; updatePagination(currentPage); console.log('切换到分类:', category); // 滚动到内容顶部 $('html, body').animate({ scrollTop: $('.page-main').offset().top - 100 }, 400); }); */ // 新闻项点击(列表项) /* $('.news-item').on('click', function() { // 跳转到新闻详情页 window.location.href = 'detail.html'; }); // 新闻卡片点击 $('.news-card').on('click', function() { // 跳转到新闻详情页 window.location.href = 'detail.html'; }); */ // 分页功能 /* let currentPage = 1; const totalPages = 4; // 总页数,实际应该从后端获取 */ // 更新分页状态 /* function updatePagination(page) { 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'); } // 滚动到列表顶部 $('html, body').animate({ scrollTop: $('.news-list').offset().top - 150 }, 400); // 这里应该通过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); } } else if (page === 'next') { if (currentPage < totalPages) { updatePagination(currentPage + 1); } } else { updatePagination(page); } }); */ // 初始化分页状态 // updatePagination(currentPage); // 新闻项hover效果由CSS处理,无需JavaScript // 滚动动画 function checkScroll() { $('.news-item, .news-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 * 100); } }); } // 初始化新闻项和卡片动画 $('.news-item, .news-card').css({ 'opacity': '0', 'transform': 'translateY(20px)', 'transition': 'all 0.5s ease' }); // 监听滚动 $(window).on('scroll', checkScroll); checkScroll(); // 页面加载时检查一次 });