Using jQuery to Create a Fixed Sidebar - JS - fixedSide.js


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(document).ready(function() {
  2. var theLoc = $('#leftNav').position().top;
  3. $(window).scroll(function() {
  4. if(theLoc >= $(document).scrollTop()) {
  5. if($('#leftNav').hasClass('fixed')) {
  6. $('#leftNav').removeClass('fixed');
  7. }
  8. } else {
  9. if(!$('#leftNav').hasClass('fixed')) {
  10. $('#leftNav').addClass('fixed');
  11. }
  12. }
  13. });
  14. });

URL: http://www.josephgiuffrida.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.