Script Works Inline But When I Move To External Doesnt Work?

- 1 answer

I just made a script for my navigation. So that it becomes a sticky navigation once it is scrolled to the top.

It works great when i have it at the bottom of my index file via <script> tags but when i try to place it in an external js file it doesnt seam to fire at all.

Full Fiddle

Heres the script:

var windw = this;
$.fn.followTo = function ( pos ) {
    var $this = this,
        $window = $(windw);
        if ($window.scrollTop() > pos) {
                position: 'fixed',
                top: "20px"
        } else {
                position: 'absolute',
                bottom: '0',
                left: '0', right:'0',
                top: 'inherit'



$('#mainNav').followTo( $(window).height() - ( $('#mainNav').innerHeight() + $('.globalHeader').innerHeight() ));


The jQuery library is missing you must add it above the external script. In the fiddle example click the javascript text in the upper right corner of the javascript code tab and choose a jquery version from the frameworks