document.addEventListener("DOMContentLoaded", function() { const loadMoreButton = document.getElementById("load-more"); const backToTopButton = document.getElementById("back-to-top"); if (loadMoreButton) { loadMoreButton.addEventListener("click", function() { let offset = parseInt(this.getAttribute("data-offset")); const searchTerm = this.getAttribute("data-term"); const limit = 40; fetch(`index.php?term=${searchTerm}&offset=${offset}`) .then(response => response.text()) .then(data => { const tempDiv = document.createElement('div'); tempDiv.innerHTML = data; const newContent = tempDiv.querySelectorAll('.icon-grid div'); newContent.forEach(item => document.querySelector('.icon-grid').appendChild(item)); // 更新偏移量 loadMoreButton.setAttribute("data-offset", offset + limit); }); }); } // 显示返回顶部按钮的逻辑 window.onscroll = function() { if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) { backToTopButton.style.display = "block"; } else { backToTopButton.style.display = "none"; } }; // 返回顶部按钮点击事件 backToTopButton.onclick = function() { window.scrollTo({ top: 0, behavior: 'smooth' }); }; }); document.getElementById('submit').addEventListener('keydown', function(event) { if (event.key === 'Enter') { searchMovies(); // 按下回车键时执行搜索 } });