我有一个脚本,可以将长页面向下滚动到该页面上的特定div。如何允许用户在滚动动画期间阻止页面滚动到指定的div?
$('html, body').animate({
scrollTop: $(ele).offset().top - 50
}, 1500);
我想在 1500 秒结束之前使用单击操作停止动画。
使用以下代码
stop is the id of the button
$( "#stop" ).click(function() {
$( "html, body" ).stop();
});
您所说的"触摸屏幕"是指在移动浏览器上?移动浏览器在click()
事件时有一些延迟响应,因此为了顺利完成此操作,您应该touchstart
或touchend
事件中捕获移动平台:
$("html, body").on('touchend click', function(){
$("html, body").stop();
});