LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Pure JavaScript Sliding Overlay Sidebar With Custom Open/Close Button

Pure JavaScript Sliding Overlay Sidebar With Custom Open/Close Button

A wonderful website design element is a sliding menu. A slide menu is an off-screen element that slides in and out of view when users want it. In general, slide menus use hamburger icons, arrows, text, or other icons to indicate their location. Slide menus allow developers to save precious website space. They also provide an opportunity to add an animation.

What Is A Slide Menu?

A slide menu is a menu which is usually hidden off-screen and activated to open and close via a trigger. This trigger is usually a button, mostly referred to as a hamburger menu. They come in all shapes and sizes, you can get slide-down menus and they can be either built using pure CSS or you can get slide menus in JavaScript.

There are many code snippets available online or on many other blogs and websites but everyone is not able to optimize your blog or website so you need some optimized code snippets. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready-to-use code and paste it where you want.

Features:

  1. Light Weight.
  2. Pure CSS Code.
  3. Cross Browser.
  4. No External Files.
  5. Fully Customizable.
  6. Responsive.
Recommended For You:
3D Rotating Images Slideshow Using Pure HTML And CSS

How To Add Pure JavaScript Sliding Overlay Sidebar With Custom Open/Close Button?

There are a few easy and understandable steps to achieve your desired functionality that we are gonna share below. Follow each step perfectly.

CSS:

<style>
.cartSidebar {height:100%;width:0;position:fixed;z-index:99;top:0;right:0;background-color:#FFF;overflow-x:hidden;padding-top:60px;transition:.5s;}
.cartSidebar a.closebtn{text-decoration:none;color:#818181;display:block;transition:.3s;position:absolute;top:0;left:20px;font-size:36px;}
.cartSidebar a.closebtn:hover{color:#f1f1f1}
@media screen and (max-height: 450px) {
.cartSidebar{padding-top:15px}
.cartSidebar a{font-size:18px}
}
</style>

JavaScript:

<script>
/* Cart Sidebar
// https://www.w3schools.com/howto/howto_js_sidenav.asp
----------------------------------------------- */
/* Set the width of the side navigation to 300px */
function openNav() {
document.getElementById("myCartSidebar").style.width = "360px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}
/* Set the width of the side navigation to 0 */
function closeNav() {
document.getElementById("myCartSidebar").style.width = "0";
document.body.style.backgroundColor = "white";
}
</script><!-- Cart Sidebar -->

HTML:

<a onclick="openNav()">Click Here To Open</a>
<div id="myCartSidebar" class="cartSidebar">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
</div>
<!-- Cart Sidebar -->

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need. Remember to add JavaScript after HTML code.

Troubleshooting the Errors:

Do it with concentration and patience. Check your all steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts or problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

Recommended For You:
Simple And Clean Double Value CSS Badges And Labels Examples

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *