当包含动画选项时,Jquery 回调不起作用(砌体插件)
我正在为我正在尝试构建的网站实现 David DeSandro 的 JQuery Masonry 插件。我试图在砌体函数上运行回调,以便在运行后我可以滚动到页面中的相关部分,但由于某种原因,当我打开动画时无法让它工作。这些文档可以在 http://desandro.com/demo/masonry/docs/#options 中查看。当我运行以下代码时,它工作正常,并且仅在砌体函数运行后才会发生警报:
$wall.masonry(
{
columnWidth: 216,
itemSelector: '.box:not(.invis)',
animate: false
},
function()
{
alert("Finished?");
}
);
但是,当我运行包含动画选项的以下代码时,警报在动画完成之前运行:
$wall.masonry(
{
columnWidth: 216,
itemSelector: '.box:not(.invis)',
animate: true,
animationOptions: {
duration: speed,
queue: false
}
},
function()
{
alert("Finished?");
}
);
我真的很感激任何人都可以提供的任何指示请告诉我如何防止警报发生,直到动画完成为止,因为我很困惑!非常感谢你的帮助,
戴夫
I am implementing David DeSandro's JQuery Masonry plugin for a site i'm trying to build. I am trying to run a callback on the masonry function so that i can scroll to the relevant part in the page after it runs but for some reason can't get it to work when I have the animation turned on. The docs can be seen at http://desandro.com/demo/masonry/docs/#options. When I run the following code it works fine and the alert only happens once the masonry function has run:
$wall.masonry(
{
columnWidth: 216,
itemSelector: '.box:not(.invis)',
animate: false
},
function()
{
alert("Finished?");
}
);
However when i run the following code with the animation options included the alert runs before the animation has finished:
$wall.masonry(
{
columnWidth: 216,
itemSelector: '.box:not(.invis)',
animate: true,
animationOptions: {
duration: speed,
queue: false
}
},
function()
{
alert("Finished?");
}
);
I would really appreciate any pointers anyone can give me as to how to prevent the alert happening until the animation has completed as i'm stumped! Thanks so much for your help,
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以做一些事情,但它要在你的意义上工作需要一个小技巧:
传递给
animationOptions
的对象可以采用一个complete
属性,该属性定义一个函数,该函数将动画完成后触发。问题是,每个块都会出现这种情况,因为每个块都是单独动画的。但你可以像这样解决这个问题:
There's something you can do, but it to work in your sense requires a small hack:
The object to
animationOptions
passed can take acomplete
property, which defines a function which will be fired after the animation is complete.The problem is, this will be the case for each and every of your blocks, since every block is animated separately. But you could get around this like so: