我正在使用 Drupal Views 通过 this 加载内容无限滚动脚本到元素的砖石样式网格中。
它无限滚动,但附加项不保留原始项的 CSS 属性。我不太确定为什么会这样。
此外,我使用 jQuery 悬停效果将内容“漂浮”在我的图像上。这是非常简单的代码。我无法想象它对这个问题有任何影响,但这里只是为了以防万一:
悬停效果的jQuery
$j('div.blog-list').on(".blog-thumbs-animate").hover(function(){
$j("img", this).stop().animate({opacity: 0.9},{queue:false,duration:75});
$j(".bhover", this).animate({opacity: 0.9},{queue:false,duration:75});
}, function() {
$j("img", this).stop().animate({opacity: 1},{queue:false,duration:75});
$j(".bhover", this).animate({opacity: 0},{queue:false,duration:75});
});
用于砌筑和无限滚动的 jQuery:
<script>
(function($){
var $container = $('.blog-list');
$container.imagesLoaded(function($){
$container.masonry({
itemSelector: 'div.pmason',
columnWidth: 320
});
}(jQuery));
$container.infinitescroll({
navSelector : '.pager', // selector for the paged navigation
nextSelector : '.pager-next a', // selector for the NEXT link (to page 2)
itemSelector : '.blog-list .node', // selector for all items you'll retrieve
animate : true,
loading: {
finishedMsg: 'No more pages to load.',
}
},
// trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
}
);
})(jQuery);
</script>
编辑:这是 CSS
.blist .pmason { width:319px; margin-right:1px; margin-bottom:1px; background:#FFF !important;}
.blist .last { margin-bottom:1px !important; margin-right:1px !important; }
.blog-thumbs-animate { position:relative !important; }
.blist .bhover { opacity:0; background:#f4f4f4; width:319px; position:absolute; bottom:0; left:0; height:100% !important; }
.bhover .inside { padding:20px; }
有人能帮忙吗?
谢谢!
最佳答案
我不知道这个无限滚动插件。但它似乎创建了新元素,而这些新元素没有 hover 事件监听器。
所以,我建议你这样做悬停事件监听器。
$j('div.blog-list').on("mouseenter",".blog-thumbs-animate", function (){
$j("img", this).stop().animate({opacity: 0.9},{queue:false,duration:75});
$j(".bhover", this).animate({opacity: 0.9},{queue:false,duration:75});
}).on("mouseleave",".blog-thumbs-animate", function () {
$j("img", this).stop().animate({opacity: 1},{queue:false,duration:75});
$j(".bhover", this).animate({opacity: 0},{queue:false,duration:75});
});
通过on
方法添加事件监听器与通过hover
方法添加事件监听器的区别在于,它不会将事件监听器直接附加到元素上,而是附加到选择器上.因此,即使您创建了新元素,此事件监听器也会匹配新元素。
此处有更多详细信息 http://api.jquery.com/on/
关于jquery - CSS 属性不适用于 jQuery 无限滚动中的附加项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25276793/