Resolve Elem Is Null in classie.js


I needed to adapt a twitter bootrap theme into my rails application. I put all of the required javascript files in vendor/assets and required them in order,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//= require jquery.js


//= require bootstrap.min.js


//= require jquery.easing.min.js


//= require classie.js


//= require cbpAnimatedHeader.js


//= require jqBootstrapValidation.js


//= require contact_me.js


//= require freelancer.js


//= require_tree .

However, I keep getting this error in my javascript console:

TypeError:elem is null ,classie.js

It turns out I needed to modify cbpAnimated header as follows,

Original:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function scrollPage() {


        var sy = scrollY();


        if ( sy >= changeHeaderOn ) {


            classie.add( header, 'navbar-shrink' );


        }


        else {


            classie.remove( header, 'navbar-shrink' );


        }


        didScroll = false;


    }

Modified,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    function scrollPage() {


        $(function(){


            $(window).scroll(function(){


                   if ($(this).scrollTop() > 300){


                        $('.navbar-default').addClass('navbar-shrink');


                   }


                   else{


                        $('.navbar-default').removeClass('navbar-shrink');


                    }


                });


            });


    }

Thanks to this stackoverflow post!

 

« Change Terminal's Title On Mac Walk through of RSA public-key encryption for beginners - Part II: Some Background On Modular Arithmetics »