In my template, I tracked up scrolland down scroll.
In upscroll, I added a few class namesin h2. In Downscroll, if it h2has a class name, I performed some tasks.
In DownscrollI used the property hasClass. But it does not get dynamically added class names.
This is the script I used
$(document).ready( function() {
var lastScrollTop = 0;
$(window).on('scroll', function(e){
var st = $(this).scrollTop();
if (st > lastScrollTop){
$(".rightclassname h2").each(function(){
var moveright = $(this).offset().top
if($(window).scrollTop() > moveright && !$(this).hasClass('reached')) {
$(this).addClass('reached');
console.log(moveright);
}
})
$(".leftclassname h2").each(function(){
var moveleft = $(this).offset().top ;
if($(window).scrollTop() > moveleft && !$(this).hasClass('reached'))
{
console.log('Moveleft');
$(this).addClass('reached');
}
})
}
else {
$(".rightclassname h2").each(function(){
var moveright = $(this).offset().top ;
if($(window).scrollTop() < moveright && !$(this).hasClass('reached')) {
$(this).addClass('reached');
console.log('right up ');
}
})
$(".leftclassname h2").each(function(){
var moveleft = $(this).offset().top ;
if($(window).scrollTop() < moveleft && !$(this).hasClass('reached'))
{
$(this).addClass('reached');
console.log('leftup');
}
})
}
lastScrollTop = st;
})
})
This code works great in down scroll. But the up scrollproperty hasClassdid not track the dynamically added class reached. So this is not working fine.
Please help me how to track a property hasClasshere.
**** Please refer to this violin Note the violin **
Downscroll, th etext . upscroll . **