- How to create a sliding menu bar
- Sources
- Omar Ghader
- #html
- Srcset Tutorial : Responsive Image HTML
- How to center a element inside div with css
- 101 CSS Sliders
- Table of Contents
- Related Articles
- Card Sliders
- Author
- Links
- Made with
- About the code
- Onboarding Screens
- Information Card Slider
- Elastic Slider
- Comparison (Before/After) Sliders
- Author
- Links
- Made with
- About the code
- Image Comparison Slider
- Author
- Links
- Made with
- About the code
- Javascriptless Before/After Slider
- Author
- Links
- Made with
- About the code
- Before After 3 Layer Image Slider
- Before After Image Slider (Vanilla JS)
- Author
- Links
- Made with
- About the code
- Split Screen UI
- Before & After Slider Gallery With SVG Masks
- HTML5 Before & After Comparison Slider
- Responsive Image Comparison Slider
- HTML5 Video Before-and-After Comparison Slider
- Image Comparison Slider
- Fullscreen Sliders
- Author
- Links
- Made with
- About a code
- Pure CSS ECommerce Slider
- Author
- Links
- Made with
- About the code
- Pure CSS Slider
- Author
- Links
- Made with
- About the code
- Slider Transition
- Author
- Links
- Made with
- About the code
- Horizontal Parallax Sliding Slider
- Author
- Links
- Made with
- About the code
- Smooth 3D Perspective Slider
- Fullscreen Hero Image Slider
- Velo.js Slider With Borders
- Popout Slider
- Responsive Parallax Drag-slider With Transparent Letters
- Fancy Slider
- Author
- HTML 5 Slider Bar Tutorial
- What Can This New Tag Do
- What Does The Slider Look Like
- How To Use It
- Basic
- Max and Min
- Set Default Position
- Set Steps
- Display Values
- How To Use With PHP
- How to build a sliding menu bar using HTML, CSS and JavaScript
- Let’s get started
- YAYYY! The basic slider is done!
- Adding some JavaScript
- Voilà it’s done!! Look who is clapping 😉
How to create a sliding menu bar
In this tutorial, I will show you how to create a sliding left panel easily using css and javascript only.
div class="container"> div class="slider open">Left Paneldiv> button class="toggle-button" onclick="toggleSlider()">< Closebutton> div> script> function toggleSlider () < var slider = document.querySelector('.slider') var buttonSlider = document.querySelector('.toggle-button') if (!slider.classList.contains('open'))< slider.classList.add('open') buttonSlider.innerHTML = ' < Close'> else < slider.classList.remove('open') buttonSlider.innerHTML = '> Open' > > script> style> .container< position: relative; width: 400px; height: 400px; background: #145677; > .slider< width: 200px; height: 400px; background: #945677; position: absolute; transition: transform 0.3s ease, opacity 0.3s ease; transform: translate3d(-200px, 0 ,0); will-change: transform; opacity:0; > .open< transform: translate3d(0, 0 ,0); opacity: 1; > .toggle-button< opacity:1; transform: translate3d(250px, 100px, 0); > style>
Sources
Omar Ghader
Fullstack web engineer and devops. Mobile web specialist
#html
Srcset Tutorial : Responsive Image HTML
How to make an image responsive? In this tutorial you will see how to use srcset to make the images responsive easily
Omar Ghader
How to center a element inside div with css
How to center a element inside div with css horizontally and vertically using flexbox
Omar Ghader
101 CSS Sliders
Collection of free HTML and CSS slider code examples: card, comparison, fullscreen, responsive, simple, etc. Update of May 2020 collection. 5 new items.
Table of Contents
Related Articles
Card Sliders
Author
Links
Made with
About the code
Onboarding Screens
A set of onboarding screens in HTML/CSS/JS. A personal experiment with layering PNG icons, CSS3 transitions, & flexbox.
Information Card Slider
HTML, CSS and JavaScript information card slider.
Made by Andy Tran
November 23, 2015
Elastic Slider
Photo slider working on desktop and mobile browsers.
Made by Taron
September 29, 2014
Comparison (Before/After) Sliders
Author
Links
Made with
About the code
Image Comparison Slider
A simple and clean image comparison slider, fully responsive and touch ready made with CSS and jQuery.
Author
Links
Made with
About the code
Javascriptless Before/After Slider
A before and after slider with only html and css.
Author
Links
Made with
About the code
Before After 3 Layer Image Slider
Playing around with a new idea using my two layer before/after image slider. Keeping it minimal. Keeping it vanilla. Like it if it’s useful 🙂
Before After Image Slider (Vanilla JS)
Vanilla JS, minimal, nice to look.
Made by Huw
July 3, 2017
Author
Links
Made with
About the code
Split Screen UI
A «split-screen» slider element with JavaScript.
Before & After Slider Gallery With SVG Masks
A little experiment for a before & after slider all inside a SVG. Masking makes it pretty simple. Since it’s all SVG, the images and captions scale nicely together. GreenSock’s Draggable and ThrowProps plugins were used for the slider control.
Made by Craig Roblewsky
April 17, 2017
HTML5 Before & After Comparison Slider
Uses customised range input for slider.
Made by Dudley Storey
October 14, 2016
Responsive Image Comparison Slider
Responsive image comparison slider with HTML, CSS and JavaScript.
Made by Ege Görgülü
August 3, 2016
HTML5 Video Before-and-After Comparison Slider
HTML5, CSS3 and JavaScript video before-and-after comparison slider.
Made by Dudley Storey
April 24, 2016
Image Comparison Slider
A handy draggable slider to quickly compare 2 images, powered by CSS3 and jQuery.
Made by CodyHouse
September 15, 2014
Fullscreen Sliders
Author
Links
Made with
About a code
Pure CSS ECommerce Slider
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About the code
Pure CSS Slider
Simple slider based on radio inputs. 100% pure HTML + CSS. Works also with arrow keys.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About the code
Slider Transition
Nice transition effect for fullscreen slider.
Author
Links
Made with
About the code
Horizontal Parallax Sliding Slider
Horizontal parallax sliding slider with Swiper.js.
Author
Links
Made with
About the code
Smooth 3D Perspective Slider
Responsive smooth 3D perspective slider on mouse move.
Fullscreen Hero Image Slider
Fullscreen hero image slider (swipe panels theme) with HTML, CSS and JavaScript.
Made by Tobias Bogliolo
June 25, 2017
Velo.js Slider With Borders
A slider interaction thing using Velocity and Velocity effects (UI Pack) to enhance the animation. Animation is triggered via arrow keys, nav click, or scrolling jack. This version includes borders as part of the interaction.
Made by Stephen Scaff
May 11, 2017
Popout Slider
Simple slider in a minimal style to show off images. Part of the image pops out on each slide.
Made by Nathan Taylor
Jannuary 22, 2017
Responsive Parallax Drag-slider With Transparent Letters
The thing is pretty easy customizable. You can safely change font, font size, font color, animation speed. The first letter of a new string in array in JS will appear on a new slide. Easy to create (or delete) a new slide: 1. Add new city in the array in JS. 2. Change number of slides variable and put a new image in scss list in CSS.
Made by Ruslan Pivovarov
October 8, 2016
Fancy Slider
- Clip-path for image masking rectangle border (webkit only).
- Blend-mode for this mask.
- Smart color system, just put your color name and value into sass map and then add proper class with this color name to elements and everything will work!
- Cool credits side-menu (click small button in the center of demo).
- Vanilla js with just
Author
HTML 5 Slider Bar Tutorial
Out of the new HTML tags one that you should be really excited about is the slider input tag. It used to be that you could only render a slider bar with a javascript library, but not anymore.
What Can This New Tag Do
The slider tag allows you to render a slider whose position represents a value in a range you specify. The most left side of the bar is the minimum value, the right most is the maximum.
Your users can slide the bar to the left or right to choose the value they like.
What Does The Slider Look Like
HTML5 Slider In Google Chrome
That was a picture of the bar in my browser but now look at it live
If you see a textbox above this sentence instead of the slider you browser does not support this tag yet.
How To Use It
Since the slider is used for users input it used the same syntax other input tags do. The type of this tag though is «range»
Basic
Max and Min
The previous snippt should be enough to show the slider, but this tag has more attributes you can use. Let’s set the range of values (max and min).
Now users can choose any number between 0 and 100.
Set Default Position
The slider has a default value of zero but if you give it a different value, when the browser renders the code, the pin will be positioned at that value. The next code will position the pin halfway between the ends of the bar.
Set Steps
What if you just want people to choose values at intervals of 5? This can easily be accomplished using the step attribute.
Display Values
How will users know what value they are choosing? That’s a good question and the answer is that you are going to have to come up with your own solution.
I wrote a simple javascript code that will show the value of the slider as you slide it.
function showValue(newValue)
And that should render this (if your browser supports it)
How To Use With PHP
Since this is an input tag all you have to do is give it a name attribute inside a form tag and get the value just like you would for a text field.
How to build a sliding menu bar using HTML, CSS and JavaScript
A menu is what you look for when you land at a website. It has options and gives you access to everything the website has to offer you. You would definitely say it is an important part of a website, right?
My friend Girish patil and I started a biweekly newsletter for fronted developers this month. The first newsletter features sliding menu bars, and so here I am writing about how we built it.
Before we begin, get a container in place for your whole webpage and design the width and height according to your requirements. Now, inside the container, you have to place a sliding menu. In this article, we’ll explain how to create a left sliding menu.
Let’s get started
The HTML code for the slider is given below. It is a basic bare version.
Slider
Twitter</a>
<a href="https:/twitter.com/s_omeal">@Supriya
@Girish
An anchor tag is used to open the menu when clicked on. This is what triggers the menu to open, so you can see why it’s called slider-trigger. The menu component is what lies in the slider-parent class.
Now design the menu bar in CSS. Pay attention to the design details.
.slider-container < position: relative; >.slider-container .slider-parent < height: 70vh; max-width: 250px; width: 100%; background: #6C7A89; position: absolute; left: -250px; top: 50px; visibility: hidden; opacity: 0; pointer-events: none; transition: .2s all linear; >.slider-container .slider-parent.active
Let’s now break down the above snippet and discuss how it works.
Maxwidth defines the maximum width up to which the div can occupy. In a smaller window, it can occupy less that 250px. The div occupies 250px when the window is stretched all the way out on the screen.
At times, the user might look at the website on a much smaller screen, so we want our div to resize accordingly.
Moving on, let’s look at why left : -250px? This is done to get that smooth sliding action for the menu. Notice that the value for left is negative, which tells us that the menu starts 250px to the left of the starting position (which is 0). So it is presently not in the visible area.
We don’t want the sliding menu to be seen at all, which is why we add opacity and make its visibility hidden. Everybody likes animation, and it gives an interesting visual feel. This animation can be done using the transition component.
YAYYY! The basic slider is done!
Now that the basic slider is done, let’s understand what happens when the slider bar is active — that is, when the anchor tag that opens the menu bar is clicked.
Focus on the active class in the CSS code given above. Notice that the values for opacity and visibility are changed. This change is made to make the slider (which was previously hidden) visible on the screen.
Also, you might wonder: why is it now left : 0? Previously, the slider was out of the screen. Now that we want the menu to start at the left side of the screen, we change the value of left to 0.
OH! The animation! Add the transition component again so that when the slider is active, it eases in from the left smoothly.
It’s done! You have designed the components, so what is the next step? JavaScript! It’ll put all this into action.
Adding some JavaScript
var sliderTrigger = document.getElementsByClassName("slider-trigger")[0];var slider = document.getElementsByClassName('slider-parent')[0];
sliderTrigger.addEventListener( "click" , function(el)
if(slider.classList.contains("active"))< slider.classList.remove("active"); >else
Let’s look into how JavaScript wraps everything and gets the slider working. We want the slider to open when the anchor tag slider-trigger is clicked. So we get that element into a variable sliderTrigger. Later on we get the whole slider element into the variable slider. Now, we add an event listener that implements a function when the sliderTrigger element is clicked.
sliderTrigger.addEventListener( "click" , function(el) <> );
The function that is written controls the mechanics of opening and closing the sliding menu bar. Remember that we had an active and a normal slider-parent class.
The hack we implement here is to add the active class when the sliderTrigger element is clicked, and remove the active class when the same element is clicked again. To do that we use the code given below, to check if the variable contains the class active.
slider.classList.contains("active")
If the value is true, we remove the class active from the list. What happens then? The sliding menu bar closes. If the value is false, we add the class active to the classlist. Now what happens? Yes, the sliding menu bar is displayed. It is that simple.
slider.classList.remove("active")
Voilà it’s done!! Look who is clapping 😉
The working of the same code is shown below in the CodePen.
While this is a basic example, I’m sending out examples of more complex and different types of sliding menu bars in my newsletter.