停止WordPress或插件在商品页面的自动滚动
Hey there, let's fix that frustrating auto-scroll issue on your WordPress product page! This kind of unwanted behavior almost always comes from a plugin (like a product preview or scroll-triggered marketing tool) or a custom script in your theme that's calling scrollTo or similar scroll methods automatically.
Here are a few actionable solutions to stop it:
You can add this code via the WordPress Customizer (under Additional CSS/JS) or use a plugin like Code Snippets to inject it site-wide (or just for product pages):
document.addEventListener('DOMContentLoaded', function() { // Override the native scrollTo method to only allow user-initiated scrolls const originalScrollTo = window.scrollTo; window.scrollTo = function() { // Check if the scroll was triggered by user actions (wheel, touch, keyboard) const isUserTriggered = event && (event.type === 'wheel' || event.type === 'touchmove' || event.type === 'keydown'); if (isUserTriggered) { originalScrollTo.apply(this, arguments); } }; // Watch for untrusted (script-initiated) scrolls and revert them let lastValidScroll = window.scrollY; window.addEventListener('scroll', function(event) { if (!event.isTrusted) { window.scrollTo(0, lastValidScroll); } else { lastValidScroll = window.scrollY; } }, { passive: false }); });
This code does two things: it blocks the scrollTo method from running unless the user initiated the scroll, and it reverts any script-triggered scrolls back to your last valid position.
If the JavaScript above doesn't stop the scroll, you can temporarily lock the page scroll to test if a script is forcing it. Add this CSS to your site's additional CSS section:
body.product-template-default { overflow: hidden !important; height: 100vh !important; }
Note: This will prevent all scrolling, so use it just to confirm the issue is script-related, then remove it or adjust it to target only the problematic page.
To get to the root of the problem:
- First, switch to a default WordPress theme (like Twenty Twenty-Four). If the auto-scroll stops, your theme has a rogue script—check its custom JS files or settings for any auto-scroll features.
- If the theme isn't the issue, disable your plugins one by one, refreshing the product page after each disable. When the scroll stops, you've found the culprit. Check that plugin's settings for an auto-scroll toggle, or reach out to its developer for help.
内容的提问来源于stack exchange,提问作者SHON WILLIAMS

