[英]How to make this script animated?
I have a scrolling script, how to make animated it? 我有一个滚动脚本,如何制作动画呢? (make it smooth)
(使其平滑)
$(document).ready(function() {
$.event.props.push("wheelDelta");
$( '#lololol' ).on( 'mousewheel DOMMouseScroll', function ( e ){
var delta = e.wheelDelta || -e.detail;
this.scrollLeft += ( delta < 0 ? 1 : -1 ) * 120;
e.preventDefault();
});
});
You can replace this line 您可以替换此行
this.scrollLeft += ( delta < 0 ? 1 : -1 ) * 120;
with 与
$(this).animate({
scrollLeft: $(this).scrollLeft() + ( delta < 0 ? 1 : -1 ) * 120
});
Optionally, you can specify second parameter for the $.fn.animate
function to provide variable animation time. (可选)您可以为
$.fn.animate
函数指定第二个参数,以提供可变的动画时间。
More info here 更多信息在这里
You can animate the scrolling by animating the scrollLeft
-property using the animate
-function of JQuery $elem.animate({ scrollLeft: value }, durationMs, 'easeFn', callbackFn)
您可以通过动画的动画滚动
scrollLeft
使用-property animate
的jQuery功能全$elem.animate({ scrollLeft: value }, durationMs, 'easeFn', callbackFn)
$(document).ready(function() {
$.event.props.push("wheelDelta");
$('#lololol').on('mousewheel DOMMouseScroll', function(e) {
e.preventDefault();
var delta = e.wheelDelta || -e.detail;
var scrollLeft = $(this).scrollLeft() + (delta < 0 ? 1 : -1) * 120;
$(this).animate({ scrollLeft: scrollLeft }, 500, 'swing', function() {
// callback fn
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.