Jump to content


Photo
- - - - -

Lock Section or Nav to top

Navigation Menu Fixed Scroll

Best Answer jmad , 12 August 2014 - 04:31 PM

Thanks.  I'll work on it.

Go to the full post


  • Please log in to reply
2 replies to this topic

#1 jmad

jmad

    Advocate

  • Members

  • 867 posts
  • LocationCentral Florida
  • Framework Version:DMS
  • Country: Country Flag

Posted 11 August 2014 - 07:43 PM

I've started trying to lock a section into place after it reaches the top of the page.  I've researched this, taken a couple quick Java/PHP intro courses and this seems simple enough but I can't get it to work.  I've added the following to the functions.php in the child theme and then this CSS.  Basically, nothing happens.  Through some other changes I managed to get the section to stick but it was cutoff in the middle of page...

 

.fixeda {
    position: fixed; 
    top: 0; 
    height: 202px; 
    z-index: 1;
}

 

 

Any help resolving this is appreciated. 

 

<?php

 

add_action( 'wp_footer', 'fixed_menu_onscroll' );
 
function fixed_menu_onscroll()
{
?>
<script>
   $(document).ready(function(){
       $(window).bind('scroll', function() {
       var navHeight = $( window ).height() - 70;
             if ($(window).scrollTop() > navHeight) {
                 $('#pl_areaunumber').addClass('fixeda');
             }
             else {
                 $('#pl_areaunumber').removeClass('fixeda');
             }
        });
    });
</script>
<?php
}

 

 



#2 Danny

Danny

    Is Awesome!

  • Moderators
  • 16289 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 12 August 2014 - 10:14 AM

You do not add scripts like that, you need to enqueue following the WordPress standards. If that doesn't work, then you will probably want to try following the instructions on this guide and see if that works.

 

http://www.sutanarya...css-and-jquery/

 

http://codex.wordpre..._enqueue_script



#3 jmad

jmad

    Advocate

  • Members

  • 867 posts
  • LocationCentral Florida
  • Framework Version:DMS
  • Country: Country Flag

Posted 12 August 2014 - 04:31 PM   Best Answer

Thanks.  I'll work on it.







Also tagged with one or more of these keywords: Navigation, Menu, Fixed, Scroll