How we can create a material type scrolling animation using HTML CSS JS? Solution: See this Material Scroll Animation With CSS and JavaScript, Scrolling Down Button.
Previously I have shared some scroll related programs, but this is a material design scrolling animation. Basically, material design is a grid-based layout with shadow combination and animation. It is introduced by Google, and nowadays you will see this type of design on every google product. Also nowadays an arrow down button for the scroll is very popular, and this program is a combination of these two things scroll and material design.
Today you will learn to create Scrolling Down Button Animation. Basically, there is a header section with a title text and a circular button with an arrow down icon. The arrow button placed half over the header and half over the container. And there are dummy heading and dummy texts in the program. When you will click on the arrow down button, then the header’s heigh will reduce and the container elements will shift upside with scrolling. And the arrow down icon will change to an arrow up icon, it for scroll down or normalize again.
So, Today I am sharing Material Scroll Animation With CSS and JavaScript. There I have used HTML to create the layout, CSS for styling, and JavaScript for functioning. This program has a cool design and smooth animation, and it is ready to use. You can use this program on your website after modification.
If you are thinking now how this Scrolling Down Button animation actually is, then see the preview given below.
Preview Of Scrolling Down and Up Animation
See this video preview to getting an idea of how this scroll effect looks like.
Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
- HTML5 CSS3 Responsive Menu
- Sticky Header Transition
- Responsive Flexbox Accordion
- Custom Select Dropdown
Material Scroll Animation Source Code
Before sharing source code, let’s talk about it. First I have created the main container div and placed two text sections, one for scroll down and one for scroll up. After that, I have created a header section and placed the title and a button inside it. Also in the HTML file, I have linked other files like CSS and JavaScript.
Now using CSS I have placed all the elements in the right place, as you can see in the preview. With CSS first I gave basic values like size, margin, padding, position, etc to all the elements. There I have linked an external SVG icon to create the arrow down and arrow up icon. I have used CSS transform command to create transformation and transition command for animation.
JavaScript handling here the toggle function in this program. It fetched the elements using document.querySelector command and stored in variables. Now JS detecting the click using .addEventListener command and activating the toggle class. Left all other things you will understand after getting the codes, I can’t explain all in writing.
For creating this program you have to create 3 files. First file for HTML, second for CSS, and third file for JavaScript. Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<!DOCTYPE html> <!-- Code By Webdevtrick ( https://webdevtrick.com ) --> <html lang="en" > <head> <meta charset="UTF-8"> <title>Material Scroll Animation | Webdevtrick.com</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> <link rel="stylesheet" href="style.css"> </head> <body> <div class='content-ctr'> <div class='header-content-ctr'> <div class='header-content'> <div class='title'>The Header</div> <div class='par'>You only see the header here. If you click the button,<br>the page will jump into the main content.<br></div> </div> </div> <div class='main-content-ctr'> <div class='main-content'> <div class='title'>The Content</div> <div class='par'>This is the main content. In this area,<br>the header will be hidden. Click the button to jump on top.</div> </div> </div> </div> <header> <div class='header-bg'></div> <div class='title'>material scroll animation</div> <div class='cta-ctr'> <div class='cta'></div> </div> </header> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ @import url(https://fonts.googleapis.com/css?family=Roboto:400,300,500); ::-webkit-scrollbar { display: none; } ::-moz-scrollbar { display: none; } html, body { height: 100%; } header { position: fixed; top: 0; height: 250px; width: 100%; pointer-events: none; } header .title { position: absolute; top: 50%; left: 80px; color: white; font-size: 40px; line-height: 40px; margin-top: -20px; transition: .3s all ease; z-index: 999; font-family: Roboto; font-weight: 300; text-transform: capitalize; } header .header-bg { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15); background: #ff0047; transition: .3s all ease; position: absolute; top: 0; right: 0; bottom: 0; left: 0; } header.active .title { font-size: 20px; -webkit-transform: translate(-30px, -85px); -moz-transform: translate(-30px, -85px); -ms-transform: translate(-30px, -85px); -o-transform: translate(-30px, -85px); transform: translate(-30px, -85px); transition: .3s all ease .15s; } header.active .header-bg { -webkit-transform: translateY(-170px); -moz-transform: translateY(-170px); -ms-transform: translateY(-170px); -o-transform: translateY(-170px); transform: translateY(-170px); background: #ff0033; transition: .3s all ease .15s; } header.active .cta-ctr { -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); transition: .5s all ease .2s; } header.active .cta:after { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); -o-transform: rotate(180deg); transform: rotate(180deg); transition: .5s all ease .2s; box-shadow: 0 -8px 12px 1px rgba(0, 0, 0, 0.15); } header .cta-ctr { position: absolute; top: 50px; right: 50px; bottom: 0; -webkit-transform-origin: bottom center; -moz-transform-origin: bottom center; -ms-transform-origin: bottom center; -o-transform-origin: bottom center; transform-origin: bottom center; -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -ms-transform: rotate(-90deg); -o-transform: rotate(-90deg); transform: rotate(-90deg); transition: .3s all ease; } header .cta { width: 60px; height: 60px; background: #fd9d08; border-radius: 50%; cursor: pointer; transition: .3s all ease; pointer-events: auto; position: relative; } header .cta:after { content: ""; box-shadow: 0 8px 12px 1px rgba(0, 0, 0, 0.15); border-radius: 50%; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: url("https://webdevtrick.com/wp-content/uploads/arrow-down.svg") no-repeat center 14px transparent; -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -ms-transform: rotate(90deg); -o-transform: rotate(90deg); transform: rotate(90deg); transition: .3s all ease; } header .cta:hover { background-color: #fabd68; } .content-ctr { width: 100%; height: 100%; background: white; overflow: scroll; position: relative; } .content-ctr.active .header-content-ctr { height: 0%; transition: .3s height ease .45s; } .content-ctr.active .header-content-ctr .title { transition: .3s all ease; opacity: 0; -webkit-transform: translateY(-20px); -moz-transform: translateY(-20px); -ms-transform: translateY(-20px); -o-transform: translateY(-20px); transform: translateY(-20px); } .content-ctr.active .header-content-ctr .par { transition: .3s all ease .05s; opacity: 0; -webkit-transform: translateY(-20px); -moz-transform: translateY(-20px); -ms-transform: translateY(-20px); -o-transform: translateY(-20px); transform: translateY(-20px); } .content-ctr.active .main-content-ctr { height: 100%; overflow: scroll; } .content-ctr.active .main-content-ctr .title { transition: .3s all ease .65s; -webkit-transform: translateY(0px); -moz-transform: translateY(0px); -ms-transform: translateY(0px); -o-transform: translateY(0px); transform: translateY(0px); opacity: 1; } .content-ctr.active .main-content-ctr .par { transition: .3s all ease .7s; -webkit-transform: translateY(0px); -moz-transform: translateY(0px); -ms-transform: translateY(0px); -o-transform: translateY(0px); transform: translateY(0px); opacity: 1; } .content-ctr .title { font-family: Roboto; margin-bottom: 30px; font-size: 34px; color: #ff0047; transition: .3s all ease; } .content-ctr .par { font-family: Roboto; font-size: 18px; line-height: 1.5; font-weight: 300; color: #777; } .content-ctr .header-content-ctr { position: relative; height: 100%; overflow: hidden; transition: .3s height ease; } .content-ctr .header-content-ctr .title { transition: .3s all ease .15s; } .content-ctr .header-content-ctr .par { transition: .3s all ease .3s; } .content-ctr .header-content { position: absolute; right: 0; bottom: 110px; left: 80px; } .content-ctr .main-content-ctr { position: relative; min-height: 0%; transition: .3s height ease; overflow: hidden; } .content-ctr .main-content-ctr .title, .content-ctr .main-content-ctr .par { opacity: 0; -webkit-transform: translateY(20px); -moz-transform: translateY(20px); -ms-transform: translateY(20px); -o-transform: translateY(20px); transform: translateY(20px); } .content-ctr .main-content { position: relative; top: 50%; right: 0; left: 0; margin-left: 50px; margin-top: -59px; } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Code By Webdevtrick ( https://webdevtrick.com ) (function() { var button, contentCtr; button = document.querySelector(".cta"); contentCtr = document.querySelector(".content-ctr"); button.addEventListener("click", function() { var header; header = this.parentElement.parentElement; header.classList.toggle("active"); return contentCtr.classList.toggle("active"); }); balapaCop("Material Scroll Animation", "#999"); }).call(this); |
That’s It. Now you have successfully created Material Scroll Animation With CSS and JavaScript, Scrolling Down Button Program. If you have any doubt or ques tion comment down below.
Thanks For Visiting, Keep Visiting.