I am very new to this stuff, so my apologies for the basic nature of the question.
I have built a tiles display for my wiki which shows articles as tiles. I have navigation buttons on the side to let folks browse the tiles (the tile container is 500px high, each tile is 250px high, there can be 6 or 7 rows of tiles that are hidden from view).
To handle the updating of my navigation buttons, I use a scroll handler I bodged together from various other SO sources, thus:
var scrollTimer;
$(".rsg_testtiles_display_macro_container").on('scroll', function() {
clearTimeout(scrollTimer);
scrollTimer = setTimeout(function() {
var RSTilesDisplayScrollResult = false;
if (!RSTilesDisplayScrollResult) {
$.each( $(".rsg_testtiles_display_macro_container .rsg_testtiles_display_surround[id]"),function(i,e) {
if (checkRSTilesDisplayView($(e),false)) {
updateRSTilesDisplayNavButton(false,e);
RSTilesDisplayScrollResult = true;
return false;
}
});
if (!RSTilesDisplayScrollResult) {
$.each( $(".rsg_testtiles_display_macro_container .rsg_testtiles_display_surround[id]"),function(i,e) {
if (checkRSTilesDisplayView($(e),true)) {
updateRSTilesDisplayNavButton(true,e);
RSTilesDisplayScrollResult = true;
return false;
}
});
}
}
}, 250);
});
My question is about scope - if I have multiple of my tiles displays on the same page, how I can rewrite this so that I'm updating the correct display and not all of them or, in this case, none of them.
I have a sense that I need to pass $this into my nested function somehow, but that never seems to work.
I have tried the following:
var tilesParentContainer = $(this);
...
scrollTimer = setTimeout(function() {
...
tilesParentContainer.each( $(".rsg_testtiles_display...
and also tried this
scrollTimer = setTimeout(function(this) {
and I either get nothing or I get an Uncaught TypeError: b.apply is not a function, which I completely do not understand.
Many thanks in advance, it's been driving me mad all week.