Onclick滑动到当前div

时间:2017-06-02 02:32:26

标签: javascript jquery-scrollify scroll-offset

目前,我在主页上有各种行,每行都有一个按钮。单击该按钮时,div将向上滑动到页面顶部。但与此同时,该按钮还添加了另一个动作。以下是我的js代码:

$( ".expandable-container-mobile").click(function() {

            var el = $(this).find('.mobile-show-section');//get the current element
            var el2 = $(this).find('.expandable');

            el.stop().slideToggle(700);//toggle the current one 
            $(this).children('.expandable').toggleClass('clicked');  


            $('.expandable').not(el2).removeClass('clicked');
            $('.mobile-show-section').not(el).stop().slideUp();//hide the rest

        });

我使用的是scrollify js $ .scrollify.move(“#name”);但它似乎不适用于div-section-name,其他实现方式也很好。

1 个答案:

答案 0 :(得分:0)

使用jQuery,一段代码 -

 function scrollToAnchor(aid){
     //get the element to be scrolled
     var el = $(this).find('.mobile-show-section');
     //then scroll it using jQuery annimation
     $('html,body').animate({scrollTop: el.offset().top},500);
  };

看看我的一些答案,

Answer1

Answer2

相关问题