Advertisement
afsarwebdev

JS Sticky Floating any section

Apr 7th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /*js for floating any section*/
  2. $(function() {
  3. var navbar = $('#ic-floating');
  4. var offset = navbar.offset();
  5.  
  6. var objectHeight = navbar.outerHeight();
  7. var windowHeight = $(window).height();
  8.  
  9. $(window).scroll(function () {
  10. var scrollTop = $(window).scrollTop() + ( windowHeight - objectHeight ); // check the visible top of the browser
  11.  
  12. if (offset.top <= scrollTop) {
  13. navbar.addClass('sticky');
  14. } else {
  15. navbar.removeClass('sticky');
  16. }
  17. });
  18. });
  19.  
  20. /*CSS*/
  21. .ic-sticky {
  22. position: fixed;
  23. bottom: 0;
  24. width: 100%;
  25. background-color: #fff;
  26. z-index: 2;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement