Advertisement
Guest User

Footer

a guest
Feb 18th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Footer</title>
  7. <style>
  8. * {
  9. box-sizing: border-box;
  10. margin: 0;
  11. padding: 0;
  12. }
  13.  
  14.  
  15. header,
  16. section,
  17. footer {
  18. float: left;
  19. position: relative;
  20. text-align: center;
  21. width: 100%;
  22. }
  23.  
  24. header {
  25. background-color: red;
  26. padding: 30px 0;
  27. }
  28.  
  29. section {
  30. align-items: center;
  31. background-color: grey;
  32. display: flex;
  33. flex-flow: column wrap;
  34. justify-content: center;
  35. height: 300px;
  36. transition: height .3s ease-in-out;
  37. }
  38.  
  39. button {
  40. border: none;
  41. cursor: pointer;
  42. padding: 10px 30px;
  43. }
  44.  
  45. footer {
  46. background-color: green;
  47. bottom: 0;
  48. padding: 30px 0;
  49. position: absolute;
  50. }
  51.  
  52. </style>
  53. </head>
  54. <body>
  55. <header>Eu sou um header</header>
  56. <section>
  57. Eu sou uma section
  58. <button type="button">Clique aqui para aumentar a section</button>
  59. </section>
  60. <footer>Eu sou um footer</footer>
  61.  
  62. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.js"></script>
  63. <script>
  64. $(() => {
  65. aumentaSetion()
  66. });
  67.  
  68. const button = document.querySelector('button')
  69. const section = document.querySelector('section')
  70. const footer = document.querySelector('footer')
  71.  
  72. function aumentaSetion() {
  73. button.addEventListener('click', function(e) {
  74. section.style.height = "1000px"
  75.  
  76. setTimeout(() => {
  77. resizeFooter()
  78. }, 500);
  79. })
  80. }
  81.  
  82. function resizeFooter() {
  83. const sectionHeight = section.offsetHeight
  84. const bodyHeight = window.innerHeight
  85.  
  86. if( sectionHeight > bodyHeight ) {
  87. footer.style.position = "relative"
  88. footer.style.bottom = "unset"
  89. }
  90.  
  91. console.log("Section Height: " + sectionHeight)
  92. console.log("Body Height: " + bodyHeight)
  93.  
  94. }
  95. </script>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement