How we can create a dual sliding panel using HTML CSS JavaScript? Solution: Check out this JavaScript Dual Sliding Panel With CSS, Responsive Panel Slide.
Previously I have shared many types of sliders, But this is a dual sliding panel which expands on click. Panel slider basically is an element which slides on click and shows the hidden content inside its. Basically, This type of panel can be used in multiple places like on review log, showing quotes, etc.
Today you will learn to create Responsive Panel Slide with dual panel. Basically, there are two panels with 50% of the screen width and you can see only a title in each panel, but when you will click on the panel it will expand by 100% and you will see a quote and a background image. There are also two arrow buttons you can see, one is left arrow and other is right.
So, Today I am sharing JavaScript Dual Sliding Panel With CSS. There is a toggle feature you can open the panel on click and also can close the panel on another click. Also, this is a responsive design, the panel becomes top to bottom aligns on small screen size devices. This program will be very informative and useful for you.
If you are thinking now how the panels actually are, then see the preview given below.
Preview Of Responsive Panel Slide
See this video preview to getting an idea of how the dual panel looks like.
Now you can see this visually, you also can see it live by pressing the button above. If you like this, then get the source code of its.
You May Also Like:
- Login and Signup Form Switch
- Before and After Image Slider
- 3D Cube Carousel With jQuery
- JavaScript Countdown Timer
JavaScript Dual Sliding Panel With CSS Source Code
Before sharing source code, let’s talk about it. First I have created all the divs and elements using HTML, on each panel, there has a heading, arrow button, quote, and an image. I have used SVG for creating the two arrow buttons, there I have not used any icon library. Also, I have used some tags between the divs like article tag, and section tag.
Now using CSS I have placed all the elements on the right place. Basically, there are two panels with 50% width first you can see only the heading and arrow. Using CSS I have hides the quote and image section firstly, you can see it after clicking then it will expand to single on 100% width. There is also a hover effect, when you will hover on any panel then its arrow icon starts moving.
For the responsive design, I have changed the position of the panels. On a desktop, the panel is placed as one in left and one in right but on a small screen, its becomes one in the top and another in the bottom. And when you will click on the panel to expand in small screen it will cover 100% of the height of the screen.
In there JavaScript handling the toggle feature. First JS fetches the panels using document.querySelector (info) and stored in variables. Now its read the click action and if the left panel has been clicked then its hide the right and expand the left panel. 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 for HTML, second for CSS, and third for JavaScript. Follow the steps to creating this 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 40 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>JS Dual Sliding Panels | Webdevtrick.com</title> <meta name="viewport" content="width=device-width"> <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <section class="panels"> <article class="panel left-panel"> <div class="panel inner-left-panel"> <p>"Success is a lousy teacher. It seduces smart people into thinking they can't lose."</p> </div> <div class="panel name"> <h1 class="title">Bill Gates</h1> <svg class="arrow arrow-left" width="40" height="40" viewBox="0 0 24 24"><path d="M0 0h24v24h-24z" fill="none"/><path d="M20 11h-12.17l5.59-5.59-1.42-1.41-8 8 8 8 1.41-1.41-5.58-5.59h12.17v-2z"/></svg> </div> </article> <article class="panel right-panel"> <div class="panel name"> <h1 class="title">Steve Jobs</h1> <svg class="arrow arrow-right" width="40" height="40" viewBox="0 0 24 24"><path d="M0 0h24v24h-24z" fill="none"/><path d="M12 4l-1.41 1.41 5.58 5.59h-12.17v2h12.17l-5.58 5.59 1.41 1.41 8-8z"/></svg> </div> <div class="panel inner-right-panel"> <p>"Design is not just what it looks like and feels like. Design is how it works."</p> </div> </article> </section> </div> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
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 236 237 238 239 240 241 242 243 244 245 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ * { box-sizing: border-box; -webkit-tap-highlight-color: rgba(255,255,255,0); overflow-x: hidden; } body { font-family: 'Montserrat'; line-height: 1.5; -webkit-font-smoothing: antialiased; } .container { height: 100vh; container: hidden; } .panels { width: 200%; } .panel { float: left; width: 50%; -webkit-perspective: 400px; perspective: 400px; display: flex; align-items: center; justify-content: center; transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1); } .left-panel, .right-panel { will-change: transform; position: relative; left: -25%; -webkit-transform: translate(0, 0); transform: translate(0, 0); } .left-panel { background: #fce77d; } .left-panel:hover .arrow { -webkit-transform: translate(-100%, -50%); transform: translate(-100%, -50%); } .right-panel { background: #f96167; } .right-panel:hover .arrow { -webkit-transform: translate(0, -50%); transform: translate(0, -50%); } .left-panel-active { -webkit-transform: translate(50%, 0); transform: translate(50%, 0); } .left-panel-active .inner-left-panel { -webkit-transform: rotateY(0); transform: rotateY(0); } .left-panel-active .arrow { -webkit-transform: translate(-50%, -50%) rotate(180deg) !important; transform: translate(-50%, -50%) rotate(180deg) !important; } .right-panel-active { -webkit-transform: translate(-50%, 0); transform: translate(-50%, 0); } .right-panel-active .inner-right-panel { -webkit-transform: rotateY(0); transform: rotateY(0); } .right-panel-active .arrow { -webkit-transform: translate(-50%, -50%) rotate(180deg) !important; transform: translate(-50%, -50%) rotate(180deg) !important; } .left-panel-hidden { -webkit-transform: translate(-50%, 0); transform: translate(-50%, 0); } .right-panel-hidden { -webkit-transform: translate(50%, 0); transform: translate(50%, 0); } .name { cursor: pointer; } .inner-left-panel, .inner-right-panel, .name { will-change: transform; padding: 0 5vw; height: 100vh; } .inner-left-panel { -webkit-transform-origin: right center; transform-origin: right center; -webkit-transform: rotateY(-90deg); transform: rotateY(-90deg); transition-delay: 0.1s; background: url("https://webdevtrick.com/wp-content/uploads/bill.jpg") center/cover; } .inner-left-panel:before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #fce77d; z-index: -1; opacity: 0.85; } .inner-right-panel { -webkit-transform-origin: left center; transform-origin: left center; -webkit-transform: rotateY(90deg); transform: rotateY(90deg); transition-delay: 0.1s; background: url("https://webdevtrick.com/wp-content/uploads/steve.jpg") center/cover; } .inner-right-panel:before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #f96167; z-index: -1; opacity: 0.85; } .title { margin: 0; font-size: 40px; text-align: center; color: #212121; } .panels p { font-size: 30px; margin: 0; } @media (max-width: 640px) { .panels { width: 100%; height: 200vh; } .panel { float: none; width: 100%; height: 100vh; display: block; text-align: center; } .left-panel, .right-panel { top: -25%; left: 0; } .left-panel:hover .arrow { -webkit-transform: translate(-50%, -80%) rotate(90deg); transform: translate(-50%, -80%) rotate(90deg); } .right-panel:hover .arrow { -webkit-transform: translate(-50%, -20%) rotate(90deg); transform: translate(-50%, -20%) rotate(90deg); } .left-panel-active { -webkit-transform: translate(0, 50%); transform: translate(0, 50%); } .left-panel-active .inner-left-panel { -webkit-transform: rotateX(0); transform: rotateX(0); } .left-panel-active .arrow { -webkit-transform: translate(-50%, -50%) rotate(-90deg) !important; transform: translate(-50%, -50%) rotate(-90deg) !important; } .right-panel-active { -webkit-transform: translate(0, -50%); transform: translate(0, -50%); } .right-panel-active .inner-right-panel { -webkit-transform: rotateX(0); transform: rotateX(0); } .right-panel-active .arrow { -webkit-transform: translate(-50%, -50%) rotate(-90deg) !important; transform: translate(-50%, -50%) rotate(-90deg) !important; } .left-panel-hidden { -webkit-transform: translate(0, -50%); transform: translate(0, -50%); } .right-panel-hidden { -webkit-transform: translate(0, 50%); transform: translate(0, 50%); } .inner-left-panel, .inner-right-panel, .name { height: 50vh; padding: 2vh 8vw; display: flex; align-items: center; justify-content: center; } .inner-left-panel { -webkit-transform-origin: center bottom; transform-origin: center bottom; -webkit-transform: rotateX(90deg); transform: rotateX(90deg); } .inner-right-panel { -webkit-transform-origin: center top; transform-origin: center top; -webkit-transform: rotateX(-90deg); transform: rotateX(-90deg); } .title { font-size: 32px; } .panels p { font-size: 20px; } } .arrow { position: absolute; top: 75%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); fill: #212121; border: 3px solid #212121; border-radius: 50%; transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1); } @media (max-width: 640px) { .arrow { -webkit-transform: translate(-50%, -50%) rotate(90deg); transform: translate(-50%, -50%) rotate(90deg); } .arrow-left { top: 25%; } } |
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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// Code By Webdevtrick ( https://webdevtrick.com ) var Panels = (function() { var panelLeft = document.querySelector('.left-panel'); var panelRight = document.querySelector('.right-panel'); var openLeft = function() { panelLeft.classList.toggle('left-panel-active'); panelRight.classList.toggle('right-panel-hidden'); }; var openRight = function() { panelRight.classList.toggle('right-panel-active'); panelLeft.classList.toggle('left-panel-hidden'); }; var bindActions = function() { panelLeft.addEventListener('click', openLeft, false); panelRight.addEventListener('click', openRight, false); }; var init = function() { bindActions(); }; return { init: init }; }()); Panels.init(); |
That’s It. Now you have successfully created JavaScript Dual Sliding Panel With CSS, Responsive Panel Slide. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.