The author has already published a carousel script, which also uses only CSS and Javascript. Now let's look at the slider script. It differs from the carousel in that only one element is visible at a time, and not several, and the elements do not scroll, but are slowly replaced by one another. And further. In this slider, only images (slides) are used as elements, therefore it is called a simple image slider.
Navigation is carried out by the arrows “Next element” or “Previous element” and indicator points. Arrows and dots can be disabled in the script settings. Elements can be displayed with a stop at the first and last element or in a cycle when the last element is again followed by the first. You can enable automatic viewing (scrolling) of elements, the duration of viewing (the interval between switching) is adjustable. When you mouse over an item, scrolling stops.
The slider automatically adjusts to any screen width of any device. You can verify this by moving left or right one of the sides of the browser.
HTML is a standard slider code, except for one: a screen is placed in front of the images, which is a plain white picture. All images and screen should be the same size. The number of images is arbitrary.
The <ul> <li> tags were used as containers, but you can use either <div> <div> or <div> <p>. Arrows and indicator points are positioned absolutely in the respective containers. For arrows, patterns in the form of triangular brackets are used, which, if desired, you can replace with your own patterns. Points are generated by the program, the number of points is equal to the number of images.
All images are stacked, one above the other, with absolute positioning in the upper left corner of the containing container. The screen prevents collapse of the outer container. All images are assigned the CSS property opacity: 0, except for the first element to which the initialization program assigns opacity: 1, thereby making it visible.
Scrolling elements is carried out by smoothly changing the opacity from 1 to 0 for the visible element and from 0 to 1 for the next invisible element. Thus, the visible element becomes invisible, and the invisible visible. The transition smoothness creates a transition property with a duration of 1s and an ease-in transition function.
In order for the slider to be adaptive to any screen width, for the images you need to specify the CSS property width: 100%. For all block containers (div, ul, li, etc.) also width: 100% or, if you need width in numerical units, then only max-width or min-width.
Styles, as usual, are included in the header. The script can be connected at the onload event or at the end of the HTML markup. The slider script file may look like this: