O
O
olegkurbatov2017-05-23 13:45:59
css
olegkurbatov, 2017-05-23 13:45:59

What are the main problems of my wretched slider?

There is a simple version of the slider that scrolls in "real time" one pixel every * milliseconds.

var sliderElement = document.getElementsByClassName('header__slider-ul');
var a = 5;

var slider = setInterval(function() {
    a = a-1;
    sliderElement[0].style.marginLeft = a + "px";
    if (a < -665) {
        a = 5;
    }
}, 100);

function sliderMouseOut() {
    slider = setInterval(function() {
        a = a-1;
        sliderElement[0].style.marginLeft = a + "px";
        if (a < -665) {
            a = 5;
        }
    }, 100);
}

function sliderMouseOver() {
    clearInterval(slider)
}

In the html itself there is a block in which there are a bunch of pictures. How can this fear be improved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Negwereth, 2017-05-23
@Negwereth

First, start using transform.
Then look towards requestAnimationFrame.
And also to understand how transitions work.

N
Nikita Kit, 2017-05-23
@ShadowOfCasper

Cycling, sir.
Swiper has freemode and in its api you can completely code autoscrolling at the desired speed.
idangero.us/swiper/demos/09-freemode.html
idangero.us/swiper/api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question