html - jquery onscroll hasClass propery not working -


in template, tracked up scroll , down scroll.

on upscroll added class names h2. in downscroll if h2 has class name did tasks.

in downscroll used hasclass property. not dynamic added class names.

this script used

    $(document).ready( function() {  var lastscrolltop = 0;  $(window).on('scroll', function(e){     var st = $(this).scrolltop();          if (st > lastscrolltop){ //down scroll                  $(".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 { //up scroll                  $(".rightclassname h2").each(function(){                     var moveright = $(this).offset().top   ;                      if($(window).scrolltop() < moveright && !$(this).hasclass('reached')) {                         $(this).addclass('reached');                         console.log('right ');                     }                 })                   $(".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 working fine in down scroll. in up scroll hasclass property not tracked dynamic added class reached. not working fine.

please me how track hasclassproperty here.

****please refer fiddle refer fiddle here**

while downscroll, cross corresponding heading th etext displayed correctly. upscroll not working.**

you have formatted 'each' 'map', time on accident... think supposed this:

var obj = {    "flammable": "inflammable",    "duh": "no duh"  };  $.each( obj, function( key, value ) {    alert( key + ": " + value );  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Comments