jquery 插件 Isotope 的回调

发布于 2024-10-26 04:42:10 字数 570 浏览 2 评论 0原文


我正在使用同位素 ( http://isotope.metafizzy.co ) 和可扩展项目,我想使用 ScrollTo 以便我可以自动滚动到新展开的项目。

我首先尝试将回调与 reLayout 方法一起使用,例如:

container.isotope('reLayout', iwannascroll(origin));

function iwannascroll(origin_with_newpos){
    $.scrollTo(origin_with_newpos, 800);                
}

origin 是一个变量,我从单击处理程序中放置“this”。
不幸的是,我总是得到对象的旧位置。

实际上,我不确定回调是否被调用得太早,或者我是否无法理解存储我的 jQuery 对象如何使其更像一个副本或“指针” ;-)

有什么想法吗?

编辑:我现在确定回调是在动画结束之前调用的,所以我的问题是:我现在如何才能完成动画?

I'm using isotope ( http://isotope.metafizzy.co ) with expandable items, and i would like to use ScrollTo so that i can automatically scroll to the newly expanded item..

I first tried to use the callback with the reLayout method, something like:

container.isotope('reLayout', iwannascroll(origin));

function iwannascroll(origin_with_newpos){
    $.scrollTo(origin_with_newpos, 800);                
}

origin being a variable where i put "this" from the click handler.
Unfortunately, i always get the old position of the object..

Actually i'm not sure if the callback is called too soon or if i'm unable to understand how storing my jQuery object makes it more like a copy or a "pointer" ;-)

Any thought ?

EDIT : i am now sure that the callback is called before the end of the animation, so my question would be : how can i now the animation has finished ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我只土不豪 2024-11-02 04:42:10

好吧,

潜入同位素代码,我发现动画选项直接传递给 animate jquery 方法,所以我向这些选项添加了完整的回调:

animationOptions: {
    duration: 4000,
    easing: 'easeInOutQuad',
    queue: false,
    complete: iwannascroll
}

然后我能够过滤我展开的对象并滚动到它:

            function iwannascroll(){
                var target = $(this);
                if (target.hasClass('expanded'))
                    $.scrollTo(target, 800);                
            }

显然它会仅当您使用 jQuery animate 方法进行动画时才有效。
如果有人知道更好的“通用”方法,我很想听听;)

allright,

sneaking in the isotope code, i found that the animation options are passed directly to the animate jquery method, so i added the complete callback to these options:

animationOptions: {
    duration: 4000,
    easing: 'easeInOutQuad',
    queue: false,
    complete: iwannascroll
}

then i was able to filter my expanded object and scroll to it :

            function iwannascroll(){
                var target = $(this);
                if (target.hasClass('expanded'))
                    $.scrollTo(target, 800);                
            }

obviously it will work only if you use the jQuery animate method for the animation..
If anyone knows a better and "universal" way, i would love to hear it ;)

生活了然无味 2024-11-02 04:42:10

同位素重新布局的回调确实触发得太早了。

我使用绑定来检测动画何时结束。

它适用于 jquery 和 css 动画引擎。

$("#isotope").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){

});

ps:当然,这必须放在常规同位素代码之后。

问候,
曼努埃尔

The callback for the Isotope reLayout fires too soon indeed.

I used bind to detect when the animation ended.

It works works for both the jquery and css animation engine.

$("#isotope").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){

});

ps: this has to be placed after the regular isotope code of course.

Greetings,
Manuel

兲鉂ぱ嘚淚 2024-11-02 04:42:10

我最近尝试用animationOptions/complete-function 来实现你的想法,但没有让它正常工作。就在那时我想出了这个,通过直接将这些 jquery 命令附加到同位素调用来完成动画。

首先加载布局/砌体显示的同位素:

container.isotope({
    itemSelector: '.selector',
    masonry: {
        columnWidth: smallWidth,
    }
}); 

..然后在第二次调用中包括重新布局/调整大小单击功能:

$('.selector').click(function(){
var $this = $(this),
    tileStyle = $this.hasClass('large') ? { width: smallWidth } : { width: largeWidth };
$this.toggleClass('large');     
$this.find('.selector').stop().animate( tileStyle );   

    // Here we search for the enlarged isotope-selector and apply the scroll
    // function to it...the item position is available to jquery at this point.
$container.isotope( 'reLayout' ).find($this).each(function() {
    var target = $(this);
    if (target.hasClass('large'))
                $.scrollTo(target, 800,{offset:-50});
    });
});

...我知道代码并不完美,自动滚动仅适用于第一个单击的项目,但当已经有一个或多个放大的项目时,则不再适用。也许有人知道如何扩展它。

I recently tried to implement your idea with the animationOptions/complete-function but didn't get it to work properly. that's when I came up with this one, getting the animation done by directly appending these jquery commands to the isotope call..

first load isotope for the layout/masonry display:

container.isotope({
    itemSelector: '.selector',
    masonry: {
        columnWidth: smallWidth,
    }
}); 

..and then in a second call include the reLayout/resizing inside a click function:

$('.selector').click(function(){
var $this = $(this),
    tileStyle = $this.hasClass('large') ? { width: smallWidth } : { width: largeWidth };
$this.toggleClass('large');     
$this.find('.selector').stop().animate( tileStyle );   

    // Here we search for the enlarged isotope-selector and apply the scroll
    // function to it...the item position is available to jquery at this point.
$container.isotope( 'reLayout' ).find($this).each(function() {
    var target = $(this);
    if (target.hasClass('large'))
                $.scrollTo(target, 800,{offset:-50});
    });
});

... I know the code isn't perfect and the auto scrolling is only working on the first clicked item, but not anymore when there's already one or more enlarged items. maybe somebody has an idea on how to extend this.

空城缀染半城烟沙 2024-11-02 04:42:10

我使用这个 hack 进行回调。也许这对你有用。

setTimeout(function(){
        $container.isotope('reLayout');
    }, 1000);

i use this hack for the callback. Maybe it works for you to.

setTimeout(function(){
        $container.isotope('reLayout');
    }, 1000);
樱&纷飞 2024-11-02 04:42:10

我能够将容器的 webkitTransitionEnd 和transitionend 事件与animationOptions.complete 回调结合起来,以在浏览器中获得所需的结果。您可以使用由这 3 个函数执行的通用函数,并将任何需要的逻辑放入其中。

I was able to tie into the webkitTransitionEnd and transitionend events of my container along with the animationOptions.complete callback to get the desired results across browsers. You can use a common function which gets executed by these 3 and put any needed logic in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文