Advertisement
srikat

Untitled

Feb 12th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. jQuery(function( $ ){
  2.  
  3. // Add 'shrink' class to site header on scrolling
  4. $( document ).on('scroll', function(){
  5.  
  6. if ( $(window).width() > 800 ) {
  7.  
  8. if ( $( document ).scrollTop() > 0 ){
  9. $( '.site-header' ).addClass( 'shrink' );
  10.  
  11. } else {
  12. $( '.site-header' ).removeClass( 'shrink' );
  13. }
  14. }
  15.  
  16. });
  17.  
  18. // Function to automatically add a top margin to the visible element below .site-header
  19. function addTopMargin() {
  20. var header_height = $( ".site-header" ).outerHeight();
  21. $( ".nav-primary" ).css( "margin-top", header_height + "px" );
  22. }
  23.  
  24. // http://stackoverflow.com/a/1974797/778809
  25. // Bind to the resize event of the window object
  26. $(window).on("resize", function () {
  27. if ( $(window).width() > 800 ) {
  28. addTopMargin();
  29. // Invoke the resize event immediately
  30. }
  31. }).resize();
  32.  
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement