You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为已实现的jQuery Marquee添加悬停暂停功能?

Hey there! Adding hover pause to your jQuery Marquee so users can click links is a smart move—let’s get this sorted with the cleanest, most reliable approach using the plugin’s built-in features.

Optimal Solution: Use the Plugin's Native Pause/Resume Methods

The jquery.marquee plugin you’re already using comes with official pause() and resume() methods—this is the best approach because it leverages the plugin’s internal animation logic, avoiding glitches that can come from custom workarounds.

Modified Code with Hover Pause

Here’s how to update your existing script to add the hover functionality:

<script src="//cdn.jsdelivr.net/jquery.marquee/1.3.1/jquery.marquee.min.js"></script>
<script>
$(document).ready(function() {
  $("#marq").fadeIn();
  $('.marquee').marquee({
    duration: 20000,
    gap: 50,
    delayBeforeStart: 2000,
    direction: 'left',
    duplicated: true
  });

  // Add hover pause/resume logic here
  $('.marquee').hover(
    // Mouse enters: pause the marquee
    function() {
      $(this).marquee('pause');
    },
    // Mouse leaves: resume the marquee
    function() {
      $(this).marquee('resume');
    }
  );
});
</script>

Why This Is the Best Approach

  • Native Compatibility: Using the plugin’s official methods ensures you won’t break its internal animation cycle—no stuck scrolling or inconsistent behavior like you might get with manual stop() calls.
  • Per-Element Control: The $(this) selector means if you have multiple marquee instances, each will pause/resume independently.
  • Lightweight & Simple: No extra dependencies or complex code—just a straightforward hover event binding.

Extra UX Tips

  • Add a pointer cursor to signal interactivity to users:
    .marquee {
      cursor: pointer;
    }
    
  • For smoother transitions (instead of an immediate pause), you could tweak the duration temporarily on hover, but an immediate pause is usually most user-friendly for link clicks.
  • Test across target browsers to confirm consistency—this plugin is well-maintained, but quick verification never hurts.

内容的提问来源于stack exchange,提问作者Scott O'connor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:31:04