2013-01-20 20 views
9

我特林改变webpage.I的默认滚动速度,数量和惯性google了很多,但不成功如何更改默认scrollspeed,scrollamount,网页的scrollinertia

幸运的是,后来,这一天,我发现a plugin,它允许我们改变滚动速度,数量,惯性只在一个特定的div标签,而不是在整个网页。

这是一个基本的代码

$(".I-WILL-APPLY-ONLY HERE").mCustomScrollbar({ 
set_width:false, 
set_height:false, 
horizontalScroll:false, 
scrollInertia:550, 
SCROLLINERTIA:"easeOutCirc", 
mouseWheel:"auto", 
    autoDraggerLength:true, 
    scrollButtons:{ 
enable:false, 
     scrollType:"continuous", 
    SCROLLSPEED:20, 
     SCROLLAMOUNT:40 
    }, 
    advanced:{ 
updateOnBrowserResize:true, 
    updateOnContentResize:false, 
     autoExpandHorizontalScroll:false, 
    autoScrollOnFocus:true 
    }, 
      callbacks:{ 
    onScrollStart:function(){}, 
    onScroll:function(){}, 
onTotalScroll:function(){}, 
    onTotalScrollBack:function(){}, 
    onTotalScrollOffset:0, 
whileScrolling:false, 
     whileScrollingInterval:30 
} 
    }); 



<div id="I-WILL-APPLY-ONLY HERE" class="I-WILL-APPLY-ONLY HERE"> 
A basic height in pixels would be defined for this element and any content appearing here will have a different scrollspeed,inertia.Mentioning heignt of this div element is compulsary,else i wont show the output </div> 

的问题是,我想整个页面,而不是仅仅withing特定的div element.Any帮助将是appreciated.Please帮我

谢谢提前

+1

全面例如什么叫“量和惯性” –

+0

试试这里滚动,http表示://manos.malihu.gr/tuts/custom-scrollbar-plugin/multiple_scrollbars_example.html 这是惯性。 Scrollamount是每次滚动时滚动的数量/%/像素。 更多的滚动量,更多的滚动(滚动速度和滚动速度之间有一个细线的差异) – Michel

+0

我无法真正解释,什么惯性正好意味着,........这里是一个例子 http:/ /当你滚动,页面滚动时,元素向上移动,并缓慢停止。 – Michel

回答

1

为什么不换你的HTML的div容器和目标,像这样:

<div class="container"> 
    <div id="I-WILL-APPLY-ONLY HERE" class="I-WILL-APPLY-ONLY HERE"> 
<!-- Content here --> 
    </div> 
</div> 

然后瞄准在了jQuery的容器类:

$('.container').mCustomScrollbar... 
+0

有意详细说明一下吗?举例说明如何做? – Veger

+0

在你的HTML中:'

',然后在jQuery中使用$(“。container”)作为目标。 –

+0

最好是*编辑*你的答案,而不是使用评论。所以你可以使用(代码)格式。 – Veger

9

您可以使用jQuery来做到这一点, 坐我拨弄一下:http://jsfiddle.net/promatik/NFk2L/

您可以添加滚动事件的事件监听器,要知道,你可能会阻止滚动的默认操作... if (event.preventDefault) event.preventDefault();

那么该事件的处理程序,使用jQuery动画,将执行滚动...

function handle(delta) { 
    var time = 1000; 
    var distance = 300; 

    $('html, body').stop().animate({ 
     scrollTop: $(window).scrollTop() - (distance * delta) 
    }, time); 
} 

您可以设置时间,距离(你也可以添加一个宽松的方法),请参阅fiddle

+0

你如何使这个功能在移动设备上工作? –