Console.log not working at all

后端 未结 13 748
故里飘歌
故里飘歌 2020-12-29 02:13

A bunch of code isn\'t working and I\'m trying to identify where the problem lies but console.log() isn\'t logging any results in Chrome Dev tools, am I doing i

13条回答
  •  猫巷女王i
    2020-12-29 02:54

    Consider a more pragmatic approach to the question of "doing it correctly".

    console.log("about to bind scroll fx");
    
    $(window).scroll(function() {
    
           console.log("scroll bound, loop through div's");
    
           $('div').each(function(){
    

    If both of those logs output correctly, then its likely the problem exists in your var declaration. To debug that, consider breaking it out into several lines:

    var id='#'+$(this).attr('id');
    
    console.log(id);
    
    var off=$(id).offset().top;
    var hei=$(id).height();
    var winscroll=$(window).scrollTop();
    var dif=hei+off-($(window).height());
    

    By doing this, at least during debugging, you may find that the var id is undefined, causing errors throughout the rest of the code. Is it possible some of your div tags do not have id's?

提交回复
热议问题