[英]Replacing scrolling with easing animation
I have been trying hard to replace the default $(window).scroll()
behavior with beautiful easing animation. 我一直在努力用漂亮的$(window).scroll()
动画替换默认的$(window).scroll()
行为。 But no luck so far. 但到目前为止没有运气。 Following is my code. 以下是我的代码。
$(window).scroll(function(e){
e.preventDefault();
var cp=$(window).scrollTop(); // current scroll position
//animate with custom easing
$('html, body').animate({scrollTop:cp}, 50,'easeInElastic');
});
But this is not working. 但这是行不通的。 It simply scrolls 1-3 pixels only and very slow. 它仅滚动1-3个像素,速度非常慢。
If i change it to $('html, body').animate({scrollTop:500}, 50,'easeInElastic');
如果我将其更改为$('html, body').animate({scrollTop:500}, 50,'easeInElastic');
it just does it once and thats not what i want. 它只做一次,那不是我想要的。
I want the replace the standard scroll behavior with easing animation when user presses the scroll-bar buttons. 我想在用户按下滚动条按钮时用缓动动画替换标准滚动行为。
JSFiddle link http://jsfiddle.net/bfDrp/ JSFiddle链接http://jsfiddle.net/bfDrp/
Take a look at this plugin: 看一下这个插件:
http://manos.malihu.gr/jquery-custom-content-scroller/ http://manos.malihu.gr/jquery-custom-content-scroller/
Here is implemintation: 这是实现:
<script>
(function($){
$(document).ready(function(){
$("body").mCustomScrollbar();
});
})(jQuery);
使用.scrollTo函数,您也可以在窗口中使用scrollX和scrollY。
window.scrollTo(0,150,500);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.