G
G
greenfox072018-08-15 17:18:04
JavaScript
greenfox07, 2018-08-15 17:18:04

How to make jquery slider without plugins?

How to write a simple jQuery slider without buttons, with automatic scrolling?
I understand that it’s easier to download a ready-made one, but I’m interested in the very essence of how it is written.

HTML

<div class="slider">
  <ul class="slider__list">
    <li class="slide active">
      <img src="img/bg/first-bg.png" alt="first-bg">
      <span class="slide__title">a v e</span>
      <button class="slide__btn btn">shop men’s collection</button>
    </li>
    <li class="slide">
      <img src="img/bg/first-bg.png" alt="first-bg">
      <span class="slide__title">a v e</span>
      <button class="slide__btn btn">shop men’s collection</button>
    </li>
    <li class="slide">
      <img src="img/bg/first-bg.png" alt="first-bg">
      <span class="slide__title">a v e</span>
      <button class="slide__btn btn">shop men’s collection</button>
    </li>
  </ul>
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Wolf, 2018-08-15
@mannaro

Well, how. All slides are hidden, then the first one is shown. Then the second is hidden and shown. And so in a circle.

D
Destell, 2018-08-16
@Destell

The simplest option that came to mind is to use setTimeout or a loop. Without considering the development of flipping for myself, I won’t say for sure, I haven’t matured yet.
We get the position of the parent block (.slider), for example, 400x400, we get the position of the active slide (.slide .active) of the same size (to make it easier to perceive), we shift the strip (.slider__list) with slides to this position. All this in a set timeout (recursive), settimer or loop, but these are offhand thoughts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question