javascript - Class alert when section's top is equal or higher than main panel's top -
i have fixed panel content scrolled , separated divs. would, when content's div top reaches panel top, alert appear div's class.
each div has class <div class="section-proceso anc1">
(both classes included on each div start section-
, anc
, if needed ant new class can added)
i have tried things no result:
if ($("div[class^='anc']").offset().top >= $('.contentpanel').offset().top){ alert($(this).attr('class')); }
use this:
$(".contentpanel").scroll(function () { $("div[class*='anc']").each(function() { $this = $(this); var topview = $('.contentpanel').offset().top; var topelement = $this.offset().top; if (topelement <= topview && !$(this).hasclass('appear')){ $(this).addclass('appear'); alert($(this).attr('class')); } if (topelement >= topview && $(this).hasclass('appear')){ $(this).removeclass('appear'); alert($(this).attr('class')); } }); });
you never see alert
last section becuase mention "when content's div top reaches panel top, alert appear div's class." , top of last section never reaches top of panel.
note: appear
class used prevent repeated alert on every scroll, see alert when reach section , when reach end of section appear
class has been removed, see alert when reach section top or bottom , don't see repeated annoying alert when scroll section form down or reverse.
Comments
Post a Comment