How to create a dual sliding panel using HTML, CSS and JavaScript

How to create a dual sliding panel using HTML, CSS and JavaScript

How to create a dual sliding panel using HTML, CSS and JavaScript? Solution: Check out this JavaScript Dual Sliding Panel With CSS, Responsive Panel Slide.

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.

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.

<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.

* {
  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.

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 CSSResponsive Panel Slide. If you have any doubt or question comment down below.

I hope this tutorial will surely help and you if you liked this tutorial, please consider sharing it with others.

Thank you !

css html javascript web-development

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

The Ultimate Guide to Web Development with HTML and CSS

The Ultimate Guide to Web Development with HTML and CSS. Learn Web Development by creating a Blog with HTML and CSS. Make a web applications using HTML5 and CSS3. Create a blog from Scratch.

Build PACMAN in Vanilla JavaScript, HTML and CSS

Vanilla JavaScript Game with HTML and CSS. A super simple walkthourgh to coding Pac-Man in vanilla JavaScript, HTML and CSS. Learn how to make Pac-Man move around the grid while avoiding walls, show you how to use the constructor method for all four ghosts to apply their unique characteristics to each one, including at what speed they move at. Clyde obviously being the slowest.

How to Code Tic-Tac-Toe Game in HTML, CSS and JavaScript

We will be coding a tic tac toe game using HTML, JavaScript & CSS. We will begin by creating the tic tac toe grid with html & css. We will use JavaScript in an object orientated style to create the tic tac toe game.

CSS Button Generator (Mini) using HTML, CSS, and JavaScript

Learn how to create a mini CSS Button generator just by using HTML, CSS, and JavaScript. We will only cover some properties related to the button but you can use other properties to allow users to play around with different styles and designs.

Introduction To HTML & CSS: Web Development For Beginners

Introduction To HTML & CSS: Web Development For Beginners - Complete HTML & CSS web developer bootcamp. Learn & practice website design using HTML5 & CSS3 web development resources