Answer the question
In order to leave comments, you need to log in
Which page builder to choose for Wopdress?
Hello, please recommend a good page builder, thanks in advance.
There is a ready-made layout that I want to integrate into WP, I used to use purely ACF and Register Post type, but this is not the best option, since the user does not have the ability to add his own blocks to the page, but only edit the existing ones.
Answer the question
In order to leave comments, you need to log in
There is a lot of room for improvement in the code shown. But your goals and scope of the task are not clear.
Offhand:
0. Why is some library not used? Not necessarily a big one like Slick, there are also easier options.
1. Think about what will happen if there are more than one sliders on the page?
2. Write jQuery-like addClass/removeClass functions (if you don't want to use classList). Working with "active" (with a space) is dangerous.
3. Transfer class names to constants. And use BEM ("item" can be found anywhere).
4. Can the number of slides and dots vary? Judging by the code - no, but why then two cycles?
5. Setting display: "block" is also dangerous, because there could theoretically be something else (flex for example).
6. The name of the currentSlide function is bad - it's not at all clear what it does. Getter or setter?
well, you can check that the index does not go beyond the boundaries of the array like this, and simply send 1 or -1 to showSlides, such as the next slide or the previous one ... and yes, everything works the same and is well read
/* Устанавливает текущий слайд */
function currentSlide() {
showSlides();
}
/* Функция увеличивает индекс на 1, показывает следующй слайд*/
function plusSlide() {
showSlides(+1);
}
/* Функция уменьшяет индекс на 1, показывает предыдущий слайд*/
function minusSlide() {
showSlides(-1);
}
/* Основная функция слайдера */
function showSlides(n = 0) {
// ставим следующий слайд вот так
slideIndex = (slideIndex + n) % slides.length < 0
? slides.length - 1
: (slideIndex + n) % slides.length
....
Why do you need optimization? Also, the task is not clear on the slider.
If you need to make a second slider on the page, then the code is no longer working.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question