Drupal.attachBehaviours 与 jQuery 无限滚动和 jQuery 砌体 [英] Drupal.attachBehaviours with jQuery infinitescroll and jQuery masonry

查看:17
本文介绍了Drupal.attachBehaviours 与 jQuery 无限滚动和 jQuery 砌体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有点绝望.我一直在阅读我在 Drupal.behaviours 上可以找到的所有内容,但显然还不够.我尝试使用无限滚动插件运行砌体网格,以将新图像附加到砌体.到目前为止,这工作正常.我想在我的网站上实现的下一件事是悬停效果(它显示图像上的信息)和后来的 fancybox 以显示更大尺寸的图像.

I am a little desperate here. I have been reading everything I was able to find on Drupal.behaviours but obviously its still not enough. I try running a masonry grid with the infinitescroll plugin to attach the new images to the masonry. This works fine so far. The next thing I wanted to implement to my website is a hover effect (which shows information on the images) and later fancybox to show the images in a huger size.

(function ($) {
    Drupal.behaviors.views_fluidgrid = {
        attach: function (context) {
            $('.views-fluidgrid-wrapper:not(.views-fluidgrid-processed)', context).addClass('views-fluidgrid-processed').each(function () {
                // hide items while loading
                var $this = $(this).css({opacity: 0}),      
                id = $(this).attr('id'),
                settings = Drupal.settings.viewsFluidGrid[id];

                $this.imagesLoaded(function() {
                    // show items after .imagesLoaded()
                    $this.animate({opacity: 1});
                    $this.masonry({
                        //the masonry settings
                    });
                });

                //implement the function of jquery.infinitescroll.min.js
                $this.infinitescroll({
                    //the infinitescroll settings
                },

                //show new items and attach behaviours in callback
                function(newElems) {
                    var newItems = $(newElems).css({opacity: 0});
                    $(newItems).imagesLoaded(function() {
                        $(newItems).animate({opacity: 1});
                        $this.masonry('appended', newItems);
                        Drupal.attachBehaviours(newItems);
                    });
                });

            });
        }
    };
})(jQuery);

现在我读到如果我希望悬停事件也发生在新添加的内容上,我需要重新附加 Drupal.behaviours.

Now I read that I need to Reattach the Drupal.behaviours if I want the hover event to also take place on the newly added content.

(function ($) {
    Drupal.behaviors.imgOverlay = {
        attach: function (context) {
            var timeout;
            $('.img_gallery').hover(function() {
                $this = $(this);
                timeout = setTimeout(change_opacity, 500);
                }, reset_opacity);

            function change_opacity() {
                //set opacity to show the desired elements
            }

            function reset_opacity() {
                clearTimeout(timeout);
                //reset opacity to 0 on desired elements
            }
        }
    };
})(jQuery)

我现在在哪里编写 Drupal.attachBehaviours() 以使其实际工作?还是有其他一些我只是没有看到 atm 的错误?我希望我写了这个问题,以便它可以理解,也许它也对其他人有所帮助,因为我经历过 drupal 7 中没有这种组合的真正官方"运行版本.

Where do I now write the Drupal.attachBehaviours() to make it work actually? Or is there some other error I just dont see atm? I hope I wrote the question so that its understandable and maybe it also helps somebody else, since I experienced that there is no real "official" running Version of this combination in drupal 7.

推荐答案

好的,解决方案其实很简单.正确编写它时,它也会运行.它当然不是 Drupal.attachBehaviours() 而是 Drupal.attachBehaviors() .所以这个组合现在有效,我终于松了一口气:).

Ok, the solution is actually pretty simple. When writing it correctly than it also runs. its of course not Drupal.attachBehaviours() but Drupal.attachBehaviors() . So this combination now works and I am finally relieved :).

这篇关于Drupal.attachBehaviours 与 jQuery 无限滚动和 jQuery 砌体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆