B
B
bbaggins2017-01-14 12:01:30
JavaScript
bbaggins, 2017-01-14 12:01:30

Why doesn't jquery want to execute ScrollToTop on click on slick plugin element?

Friends, hello everyone!
I'm confused, please help me figure it out.
With the help of slick I build a slider, the dots sign is set for the slider. Buttons appear, it is necessary that by clicking on any of the buttons, jquery scrolls the page up. What I do: I

add the required class and the second feature to slick-dots when loading:

jQuery(".slick-dots").addClass("page-scroll").attr('data-scrollid', 'up');


I scroll like this:
jQuery(".page-scroll").click(function() {
  pagcenter();
    jQuery('html, body').animate({
      scrollTop: jQuery( '#' + jQuery(this).data("scrollid") ).offset().top - 120
    }, 1000, 'swing');
  });


dots is built during page loading, see the screenshot below:
20eb3939dd784323ab6a2c3f3ec5e8af.png
Everything works fine except for scrolling, why doesn't it want to scroll... If I add class="page-scroll" data-scrollid="up" to a static element, there are no problems, it scrolls Hurrah. There was a hypothesis that the slick plugin stops the script, I don't know how to check.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bbaggins, 2017-01-14
@bbaggins

Understood. Decision:

jQuery('.name').on('beforeChange', function(event, slick, currentSlide, nextSlide) {
}

D
Dima Pautov, 2017-01-14
@bootd

You most likely need to add the class to the list when the slider is initialized. Because initially there is no such element, it is created dynamically. Then you can access this element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question