Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <div class="content">
  2. <div class="main">
  3. Main Content
  4. </div>
  5. <div class="sidebar">
  6. Sidebar
  7. </div>
  8. <div class="footer">
  9. Footer
  10. </div>
  11. </div>
  12.  
  13. #content{
  14. position:relative; /* required */
  15. height:2000px;
  16. }
  17. .main{
  18. margin-left:100px;
  19. border:1px solid rgb(120,120,120);
  20. height:1500px;
  21. }
  22. .sidebar{
  23. position:absolute; /* required */
  24. top:25px; /* required -- does NOT need to be this value, however. */
  25. left:5px; /* required -- does NOT need to be this value, however.*/
  26. border:1px solid rgb(8,8,8);
  27. background:rgba(70,70,70,.9);
  28. color:#ecebeb;
  29. width:93px;
  30. }
  31. .footer{
  32. border-top:1px solid #ff0000;
  33. height:498px;
  34. }
  35.  
  36. $(window).scroll(function(){
  37. var dist = $(window).scrollTop();
  38. var sTop = $('.sidebar').position().top;
  39. var mHeight = $('.main').height();
  40. var userDist = 100;
  41. if((sTop > (mHeight - userDist)) && (dist > (mHeight - userDist))){
  42. //the sidebar is pinned now. it won't scroll further.
  43. }else if(dist < (mHeight - userDist)){
  44. $('.sidebar').animate({
  45. top: dist + $('.sidebar').height()
  46. }, 0);
  47. }
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement