This plugin is an image slider written in pure CSS3 and HTML5. It is part of Formir Framework but can operate independently.
The slider plugin will fully work only with CSS and HTML. All of the logic is based on CSS and <input/> tag elements, that are required.
Slider have manually (button control or class name control) and automatic function of dark mode, you can set your colors for both modes.
Quick start
Copy formir-slider.min.css or formir-slider-dots.min.css file to your application direction.
Copy code below and paste into your HTML file at a <head> part.
Copy slider code below and paste into your site body and modify item items and images.
Installation
This plugin is written in less (and optional sass) dynamic preprocessor style sheet language (CSS).
It is part of Formir CSS Framework. Formir gives you an idea of how to neatly sort and attach style files before compiling them in your project during the development phase.
You can use this approach or attach the only source of slider plugin formir-slider.less.
Choice LESS or SASS
In the documentation we focus on less preprocessor, but the same file structure and mixin / variables is used for SASS (scss), to know how to install & to compile sass file go to Sass documentation
Prepare files
Start with copy all files to your root direction:
src - your application root path
less - your less or sass direction
formir
core
mixins - less mixins
display.less
flex.less
functions.less
plugins
slider.less - all style and settings for slider plugin
formir-slider.less - your root file that imports all of other files
fonts - icons for slider
slider.woff
...
Include Style
Include formir-slider.less into your project.
In this step, you can include formir-slider.less to your main less file, or move the content of formir-slider.less to your main (manifest/root) less file.
Use developer mode of less library, or compile less using backend (ex. webpack).
To use .less file on your page look at less configuration page.
Add in your <head> tag with your HTML file on developer mode:
In production mode, you can also use less npm package to compile your own min.css file. Use lessc command in bash, for example: $ npm install -g less $ lessc -x less/formir-slider.less css/formir-slider.min.css
Set up less
Slider is fully configurable, each of colors, borders etc. you can change in less file less/formir/plugins/slider.less.
Pure CSS gives us some limits, before a start, please set up a maximum number of items in your slider before compiling the project, remember The higher the number you choose, the more your CSS will weigh.
@slider-max-items: 30; // number of max count of items / items
Plugin work without JS so we control your slider with <input/> tag, each separate input for each item on the slider.
Inputs and labels are related with id and for an attribute, so for each item, we will need one input, one label for navigating (next / prev), and one label for dot (for jump). That is all the logic that you need to know.
Good to know
If you put many slider in one page use also unique ID for each <input/> tag in your slider code, also a group of <input/> must have the unique NAME attribute.
Try to not include your slider <input/> within <form> tag if you don't must, other wide you have to clean input element before sent form if you don't have any undesirable effects.
Some browsers save state of <input/> - if you do not want this future just set AUTOCOMPLETE="off" attribute to each <input/>.
Dimension and proportions control
Slider support 3 kinds of dimensions: ratio, free and fixed
Free - (not set any class) is when the ratio of your gallery will set automatically by dimension of your images, for example, if you use only toll images ratio will be the sameas the most tollest image in set.
Ratio - set by using one of 5 ratio classes (1, 2-1, 4-3, 16-9, 21-9)
Fixed - ratio use this class to fixed dimension on that you want, you must also set width and height of your slider or first of his parent.
function class
html element to add class
none
slider
ratio of gallery will be automatically set by dimensions of images
ratio-1
slider
ratio of gallery will 1 to 1
ratio-2-1
slider
ratio of gallery will 2 to 1
ratio-4-3
slider
ratio of gallery will 4 to 3
ratio-16-9
slider
ratio of gallery will 16 to 9
ratio-21-9
slider
ratio of gallery will 21 to 9
ratio-fixed
slider
with this class you can set own dimension using padding-bottom on slider-body or height
Set size of your images
There is two option of the size of the image: cover size or contain size. Look at object-fit css set.
function class
html element to add class
none
any tag inside slider above img or picture
default object-fit is set to cover
image-cover
any tag inside slider above img or picture
object-fit set to cover
image-contain
any tag inside slider above img or picture
object-fit set to contain
Animation type control
Slider support 3 types of animation, slide on sides, fade, or no-animation.
function class
html element to add class
none
slider
default animation set to slide - move: right & left
slider-fade
slider
images will fade (opacity function) form prev to next one.
no-animation
slider
will turn off animation
Fullsceen control
The slider has a function to switch to full screen mode, in that case, you can switch to this mode by clicking the button.
Look at an example (sandbox below) of how to use fullscreen switches and triggers.
Dark mode control
The slider has a function to manually switch to dark mode, you can switch to this mode by clicking the button. Dark mode will automatically turn on when the browser is using dark mode.
function class
html element to add class
none
slider
default slider is set to auto mode, dark will be use dark variables, light will be use light variables.