I'm using the following code i found from CodePen ... Im terrible at JS and I was hoping someone could help me out.
- How do I make it so the items don't repeat, at the moment, they scroll forever with 20 to a 'page' before the infinite scroll kicks in, what i would like is if there is 50 images in the array, then display those images, 20 to a page and then stop.
- I want to put the JS in a seperate file and then use PHP to loop over some results and output the images, is it possible to somehow move the div that is rendering the images out of the javascript function? so that i can put them in actually in the block in the html?
This is the code i have in the HTML portion
<div id="SlideMiddle">
<div id="grid">
<div id="grid-content"></div>
</div>
</div>
and this is the javascript
<script>
var Imgs = [
'https://tympanus.net/Development/GridLoadingEffects/images/1.jpg',
'https://tympanus.net/Development/GridLoadingEffects/images/3.jpg',
'https://d13yacurqjgara.cloudfront.net/users/64706/screenshots/1167254/attachments/152315/SUGARSKULL-01.png',
'https://tympanus.net/Development/GridLoadingEffects/images/8.jpg',
'https://tympanus.net/Development/GridLoadingEffects/images/10.png',
'https://tympanus.net/Development/GridLoadingEffects/images/14.png',
'https://tympanus.net/Development/GridLoadingEffects/images/9.jpg',
'https://tympanus.net/Development/GridLoadingEffects/images/13.png',
'https://tympanus.net/Development/GridLoadingEffects/images/12.png',
'https://tympanus.net/Development/GridLoadingEffects/images/4.jpg',
'http://www.thedrum.com/uploads/news/172673/DzrMPF_DeezerPoster_MusicSoundBetterWithYou_03.jpg'
];
$(document).ready(function(){
$grid = $('#grid-content');
$.fn.revealItems = function($items){
var iso = this.data('isotope');
var itemSelector = iso.options.itemSelector;
$items.hide();
$(this).append($items);
$items.imagesLoaded().progress(function(imgLoad, image){
var $item = $(image.img).parents(itemSelector);
$item.show();
iso.appended($item);
});
return this;
}
$grid.isotope({
containerStyle: null,
masonry:{
columnWidth: 300,
gutter: 15
},
itemSelector: '.grid-item',
filter : '*',
transitionDuration: '0.4s'
});
$grid.imagesLoaded().progress(function(){
$grid.isotope();
})
function GenerateItems(){
var items = '';
for(var i=0; i < 20; i++){
items += '<div class="grid-item c'+(i%9)+' wow fadeInUp" ><a href=""><img src="'+Imgs[i%Imgs.length]+'" /></a></div>';
}
return $(items);
}
// SimpleInfiniteScroll
function Infinite(e){
if((e.type == 'scroll') || e.type == 'click'){
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
var bottom = top + $(window).height();
var docBottom = $(document).height();
if(bottom + 50 >= docBottom){
$grid.revealItems(GenerateItems());
}
}
}
$grid.revealItems(GenerateItems());
$(window).resize(function(){
var margin=40;
var padding=15;
var columns=0;
var cWidth=300;
var windowWidth = $(window).width();
var overflow = false;
while(!overflow){
columns++;
var WidthTheory = ((cWidth*columns)+((columns+1)*padding)+margin);
if(WidthTheory > windowWidth)
overflow = true;
}
if(columns > 1)
columns--;
var GridWidth = ((cWidth*columns)+((columns+1)*padding)+margin);
if( GridWidth != $('#grid').width()){
$('#grid').width(GridWidth);
}
});
$(window).scroll(Infinite);
new WOW().init();
})
</script>