In my website I have a calendar, whenever a user hovers over a day of the calendar I want the background to change, but of course I don't want all that loading overhead to happen at page load, but rather only when the user hovers over one of the days.
I tried to do it by following what I found in this question, but it seems to only work the first time. This is what I did after modifying the plugins code as a test:
counter = 0;
$('.calendar-day').hover(
function() {
if (counter == 0) {
$('body').attr('data-background', template_url + '/images/bg_2.jpg');
counter++;
} else if (counter == 1) {
$('body').attr('data-background', template_url + '/images/bg_3.jpg');
counter++;
} else if (counter == 2) {
$('body').attr('data-background', template_url + '/images/bg_4.jpg');
counter++;
} else if (counter == 3) {
$('body').attr('data-background', template_url + '/images/bg_1.jpg');
counter = 0;
}
$('body').lazyload();
},
function() {
}
);
Even though it does trigger all the cases, the lazy loading doesn't happen and the background doesn't change after the first time. Any thoughts on this? Other approaches to managing this are welcome as well.