scrollTo with easing and a callback function

白昼怎懂夜的黑 提交于 2019-12-22 18:12:10

问题


Here is my code thus far:

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

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

            // function not working here

        });

    });

The callback function worked previously, but since I changed to the scrollTo method with easing, it doesn't any more!

Just to make it clear I only need to know how to get my callback function working again, everything else is fine.


回答1:


There is no forth parameter, but the third parameter (settings) accepts an onAfter callback

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

from the source code on settings:

 * @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.


来源:https://stackoverflow.com/questions/7506538/scrollto-with-easing-and-a-callback-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!