jquery - 带有缓动和回调函数的scrollTo

标签 jquery callback scrollto easing

这是迄今为止我的代码:

    $('.my_button').click(function() {

        $.scrollTo( '#my_anchor', 1200, {easing:'easeInOutExpo'}, function() {          

            // function not working here

        });

    });

回调函数以前可以工作,但是自从我更改为带有缓动的scrollTo方法后,它就不再起作用了!

为了明确起见,我只需要知道如何让我的回调函数再次工作,其他一切都很好。

最佳答案

没有第四个参数,但第三个参数(设置)接受 onAfter 回调

$.scrollTo( '#my_anchor', 1200, {easing:'easeInOutExpo', onAfter: function() { }});

来自设置的源代码:

 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
 *   @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *   @option {Number} duration The OVERALL length of the animation.
 *   @option {String} easing The easing method for the animation.
 *   @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *   @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
 *   @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
 *   @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *   @option {Function} onAfter Function to be called after the scrolling ends.
 *   @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.

关于jquery - 带有缓动和回调函数的scrollTo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7506538/

相关文章:

javascript - HTML jQuery - 简单的 2 个页面,JS 不工作?

javascript - 在 Bootstrap 3 Accordion 中添加动态闭合面板

javascript - bootstrap 正方形和矩形响应具有相同的高度

java - 处理 JNA 回调函数中的 va_list 参数

javascript - Bootstrap fileinput 删除所有文件 file 而不是要删除的特定预览文件

javascript - 如何提取关闭某些变量的匿名回调?

javascript - 使用ajax无需刷新页面即可显示数据库记录

javascript - scrollTo 不滚动到元素的开头

jQuery.ScrollTo/jQuery.SerialScroll 水平滚动

jQuery: anchor 加载页面然后滚动到 div