私はここで少し絶望的です。Drupal.behaviours で見つけたものはすべて読んでいますが、明らかにまだ十分ではありません。Infinitescroll プラグインを使用して石積みグリッドを実行し、新しい画像を石積みに添付してみます。これはこれまでのところうまくいきます。次に自分の Web サイトに実装したかったのは、ホバー効果 (画像に関する情報を表示する) と、後で画像をより大きなサイズで表示するためのファンシーボックスです。
(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 を再接続する必要があることを読みました。
(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 でこの組み合わせの実際の「公式」実行バージョンが存在しないことを経験したので、理解できるように質問を書いて、おそらく他の誰かにも役立つことを願っています。