【问题标题】:smooth div scroll auto scrolling autoScrollingMode: "always" not working平滑 div 滚动自动滚动 autoScrollingMode:“总是”不起作用
【发布时间】:2012-05-19 11:12:49
【问题描述】:

我使用了选项 autoScrollingMode: "always" 但当用户将鼠标移动到左侧或右侧热点上或使用鼠标滚轮时,自动滚动仍会停止。与描述相反,热点未被禁用。我怎样才能在不停止的情况下自动滚动。她是我的代码:

<script type="text/javascript">
    $(document).ready(function() {
        $("#makeMeScrollable").smoothDivScroll({ 
            mousewheelScrolling: true,
            manualContinuousScrolling: true,
            visibleHotSpotBackgrounds: "onstart",
            autoScrollingMode: "always",
            hotSpotScrollingStep: "5",
            hotSpotsVisibleTime: "2000"
        });
    });
</script>

感谢您的帮助,Afrikpit

【问题讨论】:

  • 我想补充一点,我看到了同样的问题。当您将 autoScrollingMode 设置为“始终”时,应完全禁用鼠标滚轮和热点交互,但事实并非如此。对我来说,它在 Safari 浏览器中可以正常工作,但在我测试过的所有其他浏览器中都被破坏了:Chrome、Firefox 和 Opera (Mac OS 10.9)。

标签: html scroll smooth autoscroll


【解决方案1】:

如果你想自动滚动,这个设置应该足够了:

<script type="text/javascript">
    $(document).ready(function() {
        $("#makeMeScrollable").smoothDivScroll({ 
            autoScrollingMode: "always"
        });
    });
</script>

这意味着滚动条会一直自动滚动,不受用户干扰。或者您是否在寻找不同的设置?

【讨论】:

    【解决方案2】:

    使用 autoScrollingMode: "onStart"

    【讨论】:

      【解决方案3】:

      好的,我已经通过稍微编辑源以禁用鼠标滚轮滚动来修复它。

      在 jquery.smoothDivScroll.js(不是 .min.js)的第 337-355 行,我注释掉了所有 self.stopAutoScrolling();self.move(pixels); 行:

      if (o.mousewheelScrolling === "vertical" && deltaY !== 0) {
          // Stop any ongoing auto scrolling if it's running
          // self.stopAutoScrolling();
          event.preventDefault();
          // pixels = Math.round((o.mousewheelScrollingStep * deltaY) * -1);
          // self.move(pixels);
      } else if (o.mousewheelScrolling === "horizontal" && deltaX !== 0) {
          // Stop any ongoing auto scrolling if it's running
          // self.stopAutoScrolling();
          event.preventDefault();
          // pixels = Math.round((o.mousewheelScrollingStep * deltaX) * -1);
          // self.move(pixels);
      } else if (o.mousewheelScrolling === "allDirections") {
          // Stop any ongoing auto scrolling if it's running
          // self.stopAutoScrolling();
          event.preventDefault();
          // pixels = Math.round((o.mousewheelScrollingStep * delta) * -1);
          // self.move(pixels);
      }
      

      然后我将第 364 行更改为:

      el.data("scrollingHotSpotLeft").add(el.data("scrollingHotSpotRight")).add(el.data("scrollWrapper")).mousewheel(function (event) {
      

      我刚刚添加了.add(el.data("scrollWrapper")) 部分以禁用整个区域的鼠标滚轮滚动。

      这样做使它滚动得更快一些,所以我不得不调整我的autoScrollingInterval 设置,但它似乎对我来说禁用了鼠标滚轮滚动。顶部的默认设置是禁用热点滚动的良好开端(我在 jquery.smoothDivScroll.js 顶部的选项中默认禁用它并且看不到任何热点)。

      然后只需将代码压缩回您的 jquery.smoothDivScroll.min.js 文件,您就应该进行设置。最后我的配置是这样的:

      $(document).ready(function() {
      
          $("div#makeMeScrollable").smoothDivScroll({
              manualContinuousScrolling: true,
              autoScrollingMode: "always",
              autoScrollingInterval: 80,
              autoScrollingDirection: "endlessLoopRight",
              autoScrollingStep: 1,
              hotSpotScrolling: false,
              mousewheelScrolling: "",
              touchScrolling: false
          });
      
      });
      

      【讨论】:

        猜你喜欢
        • 2014-12-19
        • 2011-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多