Drupal 7 Drupal.AttachBehavior与jQuery infinitescroll和jQuery Mashesis
我在这里有点绝望。我一直在阅读我在Drupal.Behaviors上找到的所有内容,但显然这还不够。我尝试运行带有infinitescroll插件的砖石网格,将新图像附加到砖石上。到目前为止,这一切都很好。我想在我的网站上实现的下一件事是悬停效果(显示图像上的信息),然后fancybox以更大的尺寸显示图像Drupal 7 Drupal.AttachBehavior与jQuery infinitescroll和jQuery Mashesis,drupal-7,jquery-masonry,infinite-scroll,Drupal 7,Jquery Masonry,Infinite Scroll,我在这里有点绝望。我一直在阅读我在Drupal.Behaviors上找到的所有内容,但显然这还不够。我尝试运行带有infinitescroll插件的砖石网格,将新图像附加到砖石上。到目前为止,这一切都很好。我想在我的网站上实现的下一件事是悬停效果(显示图像上的信息),然后fancybox以更大的尺寸显示图像 (function ($) { Drupal.behaviors.views_fluidgrid = { attach: function (context) {
(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.behaviors
(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.attachBehaviors()使其实际工作?还是有其他我看不到的错误?我希望我写的问题能让人理解,也许还能帮助其他人,因为我体验到drupal 7中没有这种组合的真正“官方”运行版本。好的,解决方案其实很简单。正确写入时,它也会运行。当然不是
Drupal.attachBehaviors()
,而是Drupal.attachBehaviors()
。所以这个组合现在起作用了,我终于松了一口气:)