jQuery动画回调不起作用
jQuery animation callback doesn't work
为什么不触发警报?
var $anchor = $(this);
$('.hide').val($(this).attr('href'));
$('html, body').animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, {
queue: false,
duration: 1000,
easing: 'easeInOutCirc'
}, function () {
alert('test');
});
您可以在.animate()
中使用多种不同的语法选项。当你传递一个属性对象和一个选项对象时(就像你正在做的那样),补全函数进入选项对象,而不是像这样作为第三个参数:
var $anchor = $(this);
$('.hide').val($(this).attr('href'));
$('html, body').animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, {
queue: false,
duration: 1000,
easing: 'easeInOutCirc',
complete: function () {
alert('test');
}
}
);
这在jQuery .animate()文档中有详细描述。
.animate( properties, options )
properties - A map of CSS properties that the animation will move toward.
options - A map of additional options to pass to the method. Supported keys:
duration: A string or number determining how long the animation will run.
easing: A string indicating which easing function to use for the transition.
complete: A function to call once the animation is complete.
step: A function to be called after each step of the animation.
queue: A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string.
specialEasing: A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions (added 1.4).
尝试指定第三个参数为"complete",如下所示:
var $anchor = $(this);
$('.hide').val($(this).attr('href'));
$('html, body').animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, {
queue: false,
duration: 1000,
easing: 'easeInOutCirc'
}, complete: function () {
alert('test');
});
相关文章:
- Javascript点击事件回调不起作用
- STOMP web套接字回调不'不起作用
- Angular Js 尝试从主按钮回调动态更改模态文本并且不起作用
- socket.io回调函数不起作用
- 如果我移除animateTo参数,.remove()回调函数将不起作用
- 构建Ajax调用数组时,JQueryAjax成功回调不起作用
- Javascript中的AJAX-命名回调;不起作用
- JQuery Smart Spinner:回调属性不起作用
- 类似FaceBook的按钮回调不起作用
- jQuery地址在回调中不起作用
- 回调事件不起作用-使用猫头鹰旋转木马
- spawn() 函数的“关闭”回调在 grunt 插件中不起作用
- Javascript回调函数不起作用
- 使用回调的递归Javascript函数不起作用
- j查询行在回调函数中不起作用
- 引导框.js回调不起作用
- PhoneGap 3.0.0 Tanelih 蓝牙插件在 Android 上已启用错误回调不起作用
- for循环,回调,一起超时,超时似乎不起作用
- Javascript“回调”函数不起作用
- 使用 jQuery $.ajax 的 JSONP 响应/回调不起作用