【问题标题】:mCustomScrollbar "scrollTo" not working in a single page applicationmCustomScrollbar“scrollTo”在单页应用程序中不起作用
【发布时间】:2016-03-24 17:18:09
【问题描述】:

我知道有很多这样的问题,但我找不到解决问题的方法。

在我的单页应用程序(使用 Metro 风格)中,当我从小部件返回主页时,我想将滚动位置设置回进入小部件之前的位置。

<div id="overflow" class="mCustomScrollbar _mCS_9" style="width: 1855px;">
   <div id="mCSB_9" class="mCustomScrollBox mCS-jmsHorizontalScrollbar mCSB_horizontal mCSB_inside" style="max-height: none;" tabindex="0">
      <div id="mCSB_9_container" class="mCSB_container" style="position: relative; top: 0px; left: 0px; width: 8360px;" dir="ltr">
         <div class="page" id="dashboard_all" style="width: 8360px;">
         </div>
      </div>
      <div id="mCSB_9_scrollbar_horizontal" class="mCSB_scrollTools mCSB_9_scrollbar mCS-jmsHorizontalScrollbar mCSB_scrollTools_horizontal" style="display: block;">
         <a href="#" class="mCSB_buttonLeft" oncontextmenu="return false;" style="display: block;"></a>
         <div class="mCSB_draggerContainer">
            <div id="mCSB_9_dragger_horizontal" class="mCSB_dragger" style="position: absolute; min-width: 30px; display: block; width: 403px; max-width: 1805px; left: 0px;" oncontextmenu="return false;">
               <div class="mCSB_dragger_bar"></div>
            </div>
            <div class="mCSB_draggerRail"></div>
         </div>
         <a href="#" class="mCSB_buttonRight" oncontextmenu="return false;" style="display: block;"></a>
      </div>
   </div>
</div>

这是我将插件应用到 div 时创建的代码 #overflow

$(document).ready(function() {
			$("#overflow").mCustomScrollbar({
		        axis:"x",
		        theme:"jmsHorizontalScrollbar",
		        scrollButtons: {
		        	enable: true
		        },
		        scrollInertia: 950,
				callbacks:{
					onScroll:function(){ 
						//this functions sets the value in another js file. -(this.mcs.left) to get a positive value
						getNavigator().setScrollLeft(-(this.mcs.left));
					},
					alwaysTriggerOffsets:false
				}
		      });
		})

然后我像这样使用回调中找到的位置

$("#overflow").mCustomScrollbar("scrollTo",scrollLeft);

但是什么也没发生。 如果我尝试输入 3000 之类的值,有时 #overflow 会滚动,但滚动条会停留在初始位置。

提前谢谢你, 马特奥

【问题讨论】:

    标签: javascript jquery html scrollbar mcustomscrollbar


    【解决方案1】:

    我做到了!我在 onUpdate 回调中使用了 scrollTo 方法

    onUpdate:function(){
      $("#overflow").mCustomScrollbar('scrollTo',position, {
        // scroll as soon as clicked
        timeout:0,
        // scroll duration
        scrollInertia:0,
      });
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多