How could I do a load() ajax call on a div only when this div is being actually shown by the Isotope jquery plugin?
So far my ajax calls are triggered regardless of if they are made visible by Isotope or not, which is slowing down the page a lot, since I have dozens of them:
<div id="container"><!-- starts #container -->
<div class="color-shape all red circle">
<script type="text/javascript">
$( document ).ready(function() {
jQuery('.ajax-red-circle').load('https://URL-1-HERE.com #interesting-element');
});
</script>
<div class="ajax-red-circle"></div>
</div>
<div class="color-shape all blue circle">
<script type="text/javascript">
$( document ).ready(function() {
jQuery('.ajax-blue-circle').load('https://URL-2-HERE.com #interesting-element');
});
</script>
<div class="ajax-blue-circle"></div>
</div>
<!-- ETC ETC -->
</div><!-- ends #container -->
...how to trigger them only if the div they "belong to" is actually rendered visible by Isotope?
My Isotope code is here (it combines two filters: Shape and Color):
<script type="text/javascript">
$(window).load(function() {
$(function(){
var $container = $('#container'),
filters = {};
$container.isotope({
itemSelector : '.color-shape',
filter: '.all',
});
// filter buttons
$('.filter a').click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return;
}
var $optionSet = $this.parents('.option-set');
// change selected class
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
// store filter value in object
// i.e. filters.color = 'red'
var group = $optionSet.attr('data-filter-group');
filters[ group ] = $this.attr('data-filter-value');
// convert object into array
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[ prop ] )
}
var selector = isoFilters.join('');
$container.isotope({ filter: selector });
return false;
});
});
});
</script>