Marcos_Alexandre

Sidebar Fixed

Mar 6th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* SIDEBAR FIXED */
  2.  
  3. $(function() {
  4.  
  5.     var $sidebar   = $("#ticket"),
  6.         $window    = $(window),
  7.         offset     = $sidebar.offset(),
  8.         topPadding = 250;
  9.  
  10.     $window.scroll(function() {
  11.         if ($window.scrollTop() > offset.top) {
  12.             $sidebar.stop().animate({
  13.                 marginTop: $window.scrollTop() - offset.top + topPadding
  14.             });
  15.         } else {
  16.             $sidebar.stop().animate({
  17.                 marginTop: -80
  18.  
  19.             });
  20.         }
  21.     });
  22.    
  23. });
Advertisement
Add Comment
Please, Sign In to add comment